ViewContainerRef can usually only be used after ngAfterViewInit hook. This article shows how to get access to ViewContainerRef earlier using a directive instead of template reference and ViewChild query.

#angular #angular-dynamic-components #view-container-ref #dom-manipulation

Here is how to get ViewContainerRef before @ViewChild query is evaluated
3.05 GEEK