【发布时间】:2017-11-28 10:16:39
【问题描述】:
我想使用 ng-container 从 ngFor 中调用 ng-template
我的列表是一个数组并且有一个对象列表。对象的一个属性是标题 - 在 ng-template 中可以看到。
HTML:
<ul>
<li *ngFor='let item of list;let i = index'>
<ng-container *ngTemplateOutlet="itemTemplate;context:item"></ng-container>
</li>
</ul>
<ng-template #itemTemplate let-item="item">
<p>{{ item?.title }}</p>
</ng-template>
注意:问题是 let-item 似乎未定义或为空对象。 这很奇怪,因为我把它传进去了。
【问题讨论】:
标签: angular angular5 ng-template ng-container