Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 带视图容器和templateRef的角度2插值_Angular - Fatal编程技术网

Angular 带视图容器和templateRef的角度2插值

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>

我试图模仿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>
        <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
将上下文作为第二个参数