简体   繁体   English

动态角度2负载分量并将其放置在任何位置

[英]angular 2 load component dynamically and place it anywhere

I'm using angular2 beta9 and I want to load component dynamically and place it anywhere. 我正在使用angular2 beta9,我想动态加载组件并将其放置在任何地方。 In other words, override selector. 换句话说,覆盖选择器。 I don't want to use DynamicComponentLoader.LoadAsRoot function. 我不想使用DynamicComponentLoader.LoadAsRoot函数。 Because, it's not root component and LoadAsRoot function does not call lifeCycle hooks of the component/may be it's a bug/. 因为它不是根组件,并且LoadAsRoot函数不会调用该组件的lifeCycle挂钩,否则可能是bug /。 Is there any idea to approach my goal? 有什么办法可以实现我的目标吗?

loadAsRoot() is designed for the root component only and the root component doesn't support @Input() . loadAsRoot()仅用于根组件,并且根组件不支持@Input() You can invoke this manually https://github.com/angular/angular/issues/6223#issuecomment-195155190 您可以手动调用此功能https://github.com/angular/angular/issues/6223#issuecomment-195155190

because you're wiring up everything manually you also need to manage the change detector. 因为您要手动布线,所以还需要管理变更检测器。 If you want to include the component in the application then you have to inject the ApplicationRef and to inject the ApplicationRef you have to use the long version of bootstrap 如果要在应用程序中包括该组件,则必须注入ApplicationRef并注入ApplicationRef,必须使用引导程序的长版本

I don't know of other ways. 我不知道其他方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM