我正在尝试将一个组件放入父组件中,就像在 React 中那样。
react 示例:
父组件:
<div>
Hello from parent
{this.props.children}
</div>
子组件:
<ParentComponent>
Hello from child
</ParentComponent>
基本上我要做的是在父标签之间包含子标签。
传递一个元素的@Input 浮现在我的脑海中,但这听起来非常错误和丑陋。
最佳答案
父组件:
<div>
Hello from parent
<ng-content select=".txt"></ng-content>
</div>
子组件:
<ParentComponent>
<ng-container class="txt">
Hello from child
</ng-container>
</ParentComponent>
输出: 来自家长的问候 来自 child 的问候
关于 Angular 2 : Wrapping a component inside a parent component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48593170/