我正在尝试动态创建要在 Golden Layout 中注册的组件。例如,
@ViewChild('placeholder', { read: ViewContainerRef }) viewContainerRef;
ngAfterViewInit(){
this.myLayout.registerComponent('testComponent', (container, componentState) => {
//Create an empty div on the container
container.getElement().html("<div #placeholder></div>");
this.componentFactory = this.componentFactoryResolver.resolveComponentFactory(TestComponent);
this.cmpRef = this.viewContainerRef.createComponent(this.componentFactory);
this.cmpRef.changeDetectorRef.detectChanges();
GlDirective.componentCount++;
});
}
但是,因为 viewContainerRef 指的是现在才创建的 ViewChild,所以它始终是未定义的。我们如何在 RC5 中创建一个像上面那样使用动态添加的 div 的组件。我使用@Günter Zöchbauer 对Angular 2 动态选项卡的回答以及用户单击选择的组件来得出此结论。但是不确定如何使用需要动态生成 DOM 的 Golden Layout 来实现这一点。请帮忙。