I have an issue whereby my ViewChild.nativeElement is null in all lifecycle hooks. My component looks like this:
@Component({
selector: 'connector-component',
template: `
<ng-container>
<ng-content></ng-content>
</ng-container>
`
})
export class ConnectorComponent implements AfterContentInit {
@ContentChild('ccdComponent') ccdComponent: ElementRef;
ngAfterContentInit() {
console.log(this.ccdComponent); // works as expected
console.log(this.ccdComponent.nativeElement); // null :(
}
}
This component will be invoked like this:
<connector-component>
<ccd-search #ccdComponent>
</ccd-search-component>
</connector-component>
What I would like to determine is the tagname of the #ccdComponent - in this case, ccd-search. We can guarantee that the connector-component will include a child component with the tag #ccdComponent. And, in any case, the ElementRef is populated in the lifecycle hook, but the nativeElement is null.
How do I do this?