Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular 2获取应用程序的ViewContainerRef_Javascript_Angular - Fatal编程技术网

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文件中使用选择器