I am using Dynamic Component Loader, the "loadIntoLocation" variant. But this is no longer available in latest versions of Angular2.
How to transform this code and get same functionality?
this.dcl.loadIntoLocation(OpsComponent, this._el , "dynamicpanel").then((cmp)=>{
this.compRef = cmp
// input
cmp.instance.forwarddata = { name: "teddy" }
// output
cmp.instance.emitter.subscribe(event=>{ console.log(event) })
return cmp
})
How to refactor this, keep functionality and use new Query.read instead?
Breaking change notice:
core: add Query.read and remove DynamicComponentLoader.loadIntoLocation. (efbd446)
DynamicComponentLoader.loadIntoLocationhas been removed. Use
@ViewChild(‘myVar’, read: ViewContainerRef)to get hold of a
ViewContainerRefat an element with variable
myVar`.
DynamicComponentLoader.loadIntoLocation has been removed. Use @ViewChild(‘myVar’, read: ViewContainerRef) to get hold of a ViewContainerRef at an element with variable myVar. Then call DynamicComponentLoader.loadNextToLocation. DynamicComponentLoader.loadNextToLocation now takes a ViewContainerRef instead of an ElementRef.
FINAL SOLUTION
this.resolver.resolveComponent(ChildComponent).then((factory:ComponentFactory) => {
this.compRef = this.dynamicpanel.createComponent(factory)
// input
this.compRef.instance.forwarddata = { name: "Teddy"}
// output
this.compRef.instance.emitter.subscribe(event => { this.onChildEvent(event) })
});