Angular: How to read ViewChild of a dynamically loaded component

226 Views Asked by At

I have a component which has view child like this

@ViewChild('overView') content: ElementRef;

I am loading this component dynamically like this

var overviewComponent = this.vcr.createComponent(OverviewComponent);
var content = overviewComponent.instance.content;
var nativeElement = content.nativeElement;

But I am getting content as undefined.

I want to read the nativeElement of the content

Is there any way to read it?

I even tried this but it didn't help

@ViewChild('overView', {read: ViewContainerRef}) content: ElementRef;
1

There are 1 best solutions below

0
Pawan Nogariya On

Making the content static like this worked

@ViewChild('overView', {static: true}) content: ElementRef;