我有一个关于角度子组件和父组件的问题。
我的想法是:
Parent component:
<parent-component>
<child-component1 ngFor= let car of cars>
<child-component2></child-component2>
</child-component1>
</parent-component>
看起来像父组件,在子组件1中,我可以定义子组件2的占位符吗?
例如:
child component 1
<child-component1 ngFor= let car of cars>
hier ist place holder
</child-component1>
正如您所看到的,在使用ng的子组件中,我想将car赋予子组件2。有什么解决方案吗?
有很多
使用ng-content
:https://angular.io/guide/content-projection
Parent component:
<parent-component>
<child-component1>
<child-component2></child-component2>
</child-component1>
</parent-component>
child component 1
<div>Some stuff here</div>
<ng-content></ng-content> // <= this renders child-component2
<div>Other stuff here</div>