简体   繁体   中英

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. In other words, override selector. I don't want to use DynamicComponentLoader.LoadAsRoot function. Because, it's not root component and LoadAsRoot function does not call lifeCycle hooks of the component/may be it's a 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() . You can invoke this manually 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

I don't know of other ways.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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