小编Ser*_*tov的帖子

角6创建TemplateRef的实例

我有(角度6)组件和TemplateRef<any>类型的输入参数

class TestComponent {
    @Input() tpl: TemplateRef<any>;
    ...
}
Run Code Online (Sandbox Code Playgroud)

现在,我想创建一个测试,但找不到如何在测试中创建模板并将其设置为输入字段的方法。

在我的HTML中,我有类似的模板

<test>
    <ng-template #tpl>
        <div>OLOLO</div>
    </ng-template>
</test>
Run Code Online (Sandbox Code Playgroud)

我需要这样的东西

fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
component.template = here I need instance of TemplateRef
Run Code Online (Sandbox Code Playgroud)

谢谢

javascript testing typescript angular6

5
推荐指数
1
解决办法
722
查看次数

标签 统计

angular6 ×1

javascript ×1

testing ×1

typescript ×1