在没有ViewChild查询的情况下获取/创建ViewContainerRef

时间:2017-05-15 11:29:30

标签: angular

我正在使用D3创建布局,并且我试图将Angular组件动态插入到结构中。

我设法使用注入父组件的ViewContainerRef动态创建组件:

constructor(vcRef: ViewContainerRef...

我也可以从模板中的html元素获得一个ViewContainerRef,如下所示:

@ViewChild('htmlElementINeed', { read: ViewContainerRef }) targetConterinRef;

然而,由于我动态创建html元素我需要使用D3的组件,我不能使用注入的ViewContainerRef,或者使用{{1从模板中获取ViewContainerRef }}

角度文档lists these as the two ways to access it:

  

要访问Element的ViewContainerRef,您可以在Element上放置一个使用ViewContainerRef注入的Directive,也可以通过ViewChild查询获取它。

有没有办法手动创建ViewContainerRef,或者为模板中未定义的元素获取一个?是否限制Angular我只能在编译时已经在模板中的html元素上动态创建组件?

0 个答案:

没有答案
相关问题