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