Angular 带视图容器和templateRef的角度2插值
我试图模仿ngfor的分页指令。不显示任何插值。在我的指示中,我有:Angular 带视图容器和templateRef的角度2插值,angular,Angular,我试图模仿ngfor的分页指令。不显示任何插值。在我的指示中,我有: Input() set pageOf(a){ for(let x of a) { this.viewContainer.createEmbeddedView(this.templateRef); } } 在我的html中,我有: <table> <tr *page="let a of test" > <td>abc</td>
Input() set pageOf(a){
for(let x of a) {
this.viewContainer.createEmbeddedView(this.templateRef);
}
}
在我的html中,我有:
<table>
<tr *page="let a of test" >
<td>abc</td>
<td>{{a}}</td>
</tr>
</table>
abc
{{a}
对于测试中的每个元素,“abc”显示得很好,但是{{a}}插值到的内容不显示。我的猜测是,不知何故,我需要告诉视图容器a是什么。找到了我自己的答案……以防有人在看
@Input() set pageOf(a){
for(let x of a) {
const view = this.viewContainer.createEmbeddedView(this.templateRef);
view.context.$implicit = x;
}
}
对于任何其他参数:
createEmbeddedView
将上下文作为第二个参数