Angular 2插值与视图容器和templateRef

时间:2016-10-06 16:07:10

标签: angular

我正在尝试模仿寻呼指令。不显示任何插值。在我的指示中,我有:

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}}插值到的内容不显示。我的猜测是某种程度上我需要告诉视容容器是什么。

1 个答案:

答案 0 :(得分:3)

找到我自己的答案......万一有人在看。

@Input() set pageOf(a){
    for(let x of a) {
        const view = this.viewContainer.createEmbeddedView(this.templateRef);
        view.context.$implicit = x;
    }
}