0
我想动态创建一个模态组件并将该组件附加到body或我的根元素。Angular 2获取应用程序的ViewContainerRef
我知道,当你需要动态添加组件时,你需要一个ViewContainerRef
。
例如:
createComponent(type) {
this.container.clear();
const factory: ComponentFactory = this.resolver.resolveComponentFactory(AlertComponent);
this.componentRef: ComponentRef = this.container.createComponent(factory);
}
如何追加成分的根组件?