PrimeNG将数据从动态对话框发送到其父组件



我有一个功能齐全的PrimeNG对话框在工作。我用DynamicDialogService.open将数据传递给它,但我们如何将数据发送回父级?

我能看到的文档中没有显示正在发回的数据。

this.dialogService.open(SomeModalComponent, {
...
data: {
someData: 'some string'
},
}

在对话框中,我们使用数据

ngOnInit(): void {
console.log(this.config?.data?.someData); // 'some string'
}
  1. 在父组件ref: DynamicDialogRef;中添加ref
  2. 在组件提供程序中添加DialogService
  3. 打开对话框:
this.ref = this.dialogService.open(UploadFilesDialogComponent, {
header: this.translate.instant('INVOICES.attachFiles'),
width: '30vw',
contentStyle: { "max-height": "500px", "overflow": "auto" },
data: this.invoiceFiles,
closable: false
});
  1. 在对话框组件public ref: DynamicDialogRef中注入DynamicDialogRef
  2. 在对话框组件中,使用close()函数发回数据:this.ref.close(this.uploadedFiles)
  3. 在父组件中
this.ref.onClose.subscribe((files: customUploadFile[]) => {
// put your code here
});

最新更新