Angular: DynamicComponentLoader loadIntoLocation 在 2.0.0.beta.1 中无法正常工作

创建于 2016-01-11  ·  3评论  ·  资料来源: angular/angular

 Error during instantiation of AppComponent!.
There is no component directive at element [object Object]

它适用于版本 beta.0:
http://plnkr.co/edit/p6w6bBZfkvXIdDabc1vI?p=preview
它在版本 beta.1 上被破坏了:
http://plnkr.co/edit/3Gn9ZuyMHUdlRqEmqVF7?p=preview

最有用的评论

根据突破性变化

Component view is not yet created when component constructor is called. -> use onInit lifecycle callback to access the view of a component

因此,将您的代码移动到ngOnInit可以正常工作

    ngOnInit() {
      this.dcl.loadIntoLocation(ChildComponent, this.elementRef, 'child');
    }

所有3条评论

根据突破性变化

Component view is not yet created when component constructor is called. -> use onInit lifecycle callback to access the view of a component

因此,将您的代码移动到ngOnInit可以正常工作

    ngOnInit() {
      this.dcl.loadIntoLocation(ChildComponent, this.elementRef, 'child');
    }

@ericmartinezr谢谢。

由于不活动,此问题已自动锁定。
如果您遇到类似或相关的问题,请提交新问题。

阅读有关我们的自动对话锁定政策的更多信息。

_此操作已由机器人自动执行。_

此页面是否有帮助?
0 / 5 - 0 等级