【发布时间】:2018-03-28 01:04:23
【问题描述】:
我需要在另一个组件中重复一个组件,比如说:
组件 A 在其 ng-content 中只接受 B 类型的组件。
做类似的事情:
<component-a>
<ng-template ngFor [ngForOf]="items">
<component-B></component-B>
</ng-template>
</component-a>
或者这个:
<component-a>
<ng-container *ngFor="let item of items">
<component-B></component-B>
</ng-container>
</component-a>
没有用...
我无法修改组件-a 或组件-B,并且这些方法不会渲染组件-B...
任何想法如何克服这个问题?
谢谢。
PS:我可能需要为每个项目添加多个组件-B。
【问题讨论】:
-
你的意思是
ng-container不是ng-template吗?我写下了不同之处,因为我一直弄错:blog.jonrshar.pe/2017/May/20/angular-ng-elements.html -
将数组作为参数传递给内部组件,在内部组件的模板中重复。
-
问题已编辑。我无法修改组件-b。
-
您需要将
ng-template替换为ng-container。 -
@Blauhirn 正如我在问题中所述,我也已经尝试过使用 ng-container。不过还是谢谢。
标签: angular angular2-ngcontent