【发布时间】:2019-09-18 20:24:39
【问题描述】:
我的 Angular 应用程序中有一个应用程序组件。
@Component({
selector: my-container',
template: `<div [innerHTML]="infoComponentHtml"></div>`
})
export class MyContainerComponent implements AfterViewInit {
@Input() infoComponentHtml: string = "";
constructor(private componentFactoryResolver: ComponentFactoryResolver){
}
ngAfterViewInit(): void {
if(this.infoComponentHtml){
??????
append this.infoComponentHtml dynamically
}
else{
??????
append "<default-content></default-content>" dynamically
}
}
}
this.infoComponentHtml 格式是这样的"<component-name></component-name>"
this.infoComponentHtml 是来自另一个组件的第三方组件。所以我不知道它的组件类名。
如何编译和添加附加组件?
【问题讨论】: