Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.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
Angular 角度向动态组件中注入数据@输入被传递到mat对话框组件_Angular_Angular Material - Fatal编程技术网

Angular 角度向动态组件中注入数据@输入被传递到mat对话框组件

Angular 角度向动态组件中注入数据@输入被传递到mat对话框组件,angular,angular-material,Angular,Angular Material,在这种情况下,我需要在动态对话框组件中显示一个动态表组件 动态对话框可以接收要在其中显示的另一个组件。这是通过MatDialogConfig数据属性实现的 这在我的对话框的模板中: <ng-container *ngComponentOutlet="dialogPassedPayload.additionalData"></ng-container> const compFactory=this.compFactRes.resolveComponentFactory(C

在这种情况下,我需要在动态对话框组件中显示一个动态表组件

动态对话框可以接收要在其中显示的另一个组件。这是通过MatDialogConfig数据属性实现的

这在我的对话框的模板中:

<ng-container *ngComponentOutlet="dialogPassedPayload.additionalData"></ng-container>
const compFactory=this.compFactRes.resolveComponentFactory(ComponentClassName);
const compRef=compFactory.create(this.injector);
const compInstance:any=compRef.instance;
compInstance.data=数据//你可以在这里传递数据
this.appRef.attachView(compRef.hostView);
const compElement=(compRef.hostView作为EmbeddedViewRef)。根节点[0]作为HtmleElement;//在这里,您将获得组件html,您可以将其附加到angular应用程序中的任何位置
我想这会解决你的问题。如果在服务函数中编写此函数,则也可以从其他位置调用它。

const compFactory=this.compFactRes.resolveComponentFactory(ComponentClassName);
const compRef=compFactory.create(this.injector);
const compInstance:any=compRef.instance;
compInstance.data=数据//你可以在这里传递数据
this.appRef.attachView(compRef.hostView);
const compElement=(compRef.hostView作为EmbeddedViewRef)。根节点[0]作为HtmleElement;//在这里,您将获得组件html,您可以将其附加到angular应用程序中的任何位置

我想这会解决你的问题。如果您是在服务函数中编写的,那么您也可以从其他地方调用它。

谢谢您的评论,但这并不能解决错误。与以前相同的错误消息我现在实际上重复了这个错误:error NullInjectorError:StaticInjectorError(AppModule)[BaseTableComponent->ComponentRef]:StaticInjectorError(Platform:core)[BaseTableComponent->ComponentRef]:感谢您的评论,但这并没有解决错误。与以前相同的错误消息我现在实际重复此错误:错误NullInjectorError:StaticInjectorError(AppModule)[BaseTableComponent->ComponentRef]:StaticInjectorError(平台:核心)[BaseTableComponent->ComponentRef]:
const compFactory = this.compFactRes.resolveComponentFactory(ComponentClassName);
const compRef = compFactory.create(this.injector);
const compInstance: any = compRef.instance;
compInstance.data = data; //you can pass data here
this.appRef.attachView(compRef.hostView);
const compElement = (compRef.hostView as EmbeddedViewRef<any>).rootNodes[0] as HTMLElement; // here you are getting the component html you can append it to anywhere in the angular app