The issue is in the timing. dynamicLoader is defined as ViewChild
and because of that is available only after the AfterViewInit
lifecycle hook and undefined during OnInit
. Just switch ngOnInit
to ngAfterViewInit
and you should be good to go.