【发布时间】:2017-05-05 12:24:06
【问题描述】:
我正在尝试将嵌入的内容绑定到组件循环内的变量,但我无法这样做。
我查看了 PrimeNG 的 dropdowncomponent,他们使用 template 标签和 let-car 绑定到循环的 car 变量。
但是,当我尝试这个时,我什至无法让内容嵌入。实现这一目标的正确方法是什么?
尝试:
<!-- Obviously not gonna work -->
<comp>
<span>{{option.name}}, {{option.type}}</span>
</comp>
<!-- Thought this would work but it doesn't, in odd scenarios I get the last element of the loop to transclude content and bind correctly. -->
<comp>
<template let-option>
<span>{{option.name}}, {{option.type}}</span>
</template>
</comp>
在组件中:
<ul>
<li *ngFor="let option of options">
<ng-content></ng-content>
</li>
</ul>
我想要实现的简单plunkr:
【问题讨论】:
-
在 cmets 中找到了一个完整的例子
标签: angular typescript