错误TypeError:无法读取未定义的.ngAfterViewInit动态加载程序的属性'createComponent'

时间:2019-05-16 04:52:32

标签: angular

我正在尝试将一个组件动态加载到烤面包机的另一个子组件中。因此,作为组件的烤面包机将在其内容区域中加载另一个组件。

根据本文尝试:https://blog.angularindepth.com/here-is-how-to-get-viewcontainerref-before-viewchild-query-is-evaluated-f649e51315fb

没有指令。如果有效,那么我将尝试使用这些指令。

<ng-template #regularContent>
    <div class="sn-content" [innerHTML]="content"></div>  
    <div #target></div>              
</ng-template>

@ViewChild('target', {read: ViewContainerRef}) vc: ViewContainerRef;

ngAfterViewInit() {
  const factory = this.componentFactoryResolver.resolveComponentFactory(TestComponetComponent);
  this.vc.createComponent(factory);
}

0 个答案:

没有答案