Javascript Angular 2获取应用程序的ViewContainerRef
我想动态创建一个模态组件,并将该组件附加到主体或我的根元素 我知道,当您需要动态添加组件时,您需要一个Javascript Angular 2获取应用程序的ViewContainerRef,javascript,angular,Javascript,Angular,我想动态创建一个模态组件,并将该组件附加到主体或我的根元素 我知道,当您需要动态添加组件时,您需要一个ViewContainerRef 例如: createComponent(type) { this.container.clear(); const factory: ComponentFactory = this.resolver.resolveComponentFactory(AlertComponent); this.componentRef: Component
ViewContainerRef
例如:
createComponent(type) {
this.container.clear();
const factory: ComponentFactory = this.resolver.resolveComponentFactory(AlertComponent);
this.componentRef: ComponentRef = this.container.createComponent(factory);
}
如何将组件附加到根组件 您应该在根组件html文件中使用选择器