I have a component. I need locate node in the template, append child node to located node and dynamically create some component inside the child node.
Is it possible with Angular 2?
If the node exists in the template statically the solution is known.
export class AppComponent {
@ViewChild("node", { read: ViewContainerRef }) nodeView;
..............
ngOnInit(): void {
this. componentResolver.resolveComponent(MyComponent)
.then((factory: ComponentFactory<MyComponent>) => {
MyComponent instance = this.nodeView.createComponent(factory);
});
}
}
In that way the problem is to find dynamic
equivalent of @ViewChild directive.