@ViewChild(ComponentType) comp!: ComponentType;
ngAfterViewInit() {
console.log('ComponentType instance', comp);
}
To get hold of a child component's instance, I know that ViewChild
can be used as shown above. It works for statically added components, but if I use it on a dynamically added component as demonstrated here on StackBlitz, I get undefined on ngAfterViewInit
.
What's the proper way to get hold of a dynamically loaded child component's instance?