【发布时间】:2018-07-13 13:46:15
【问题描述】:
我正在尝试将组件放入父组件中,就像在 React 中一样。
反应示例:
父组件:
<div>
Hello from parent
{this.props.children}
</div>
子组件:
<ParentComponent>
Hello from child
</ParentComponent>
基本上我要做的是在父标签之间包含子标签。
我想到了传递元素的@Input,但它听起来非常错误和丑陋。
【问题讨论】:
-
您需要在 html 中使用组件的选择器。建议看官方教程:angular.io/tutorial/toh-pt1#show-the-heroescomponent-view
-
我已经完成了教程。在另一个组件中包含一个组件,是的。但我希望将父组件包含在子组件中,并将子组件内容放置到父组件中的指定占位符。
标签: angular angular-components