我有一个功能齐全的PrimeNG对话框在工作。我用DynamicDialogService.open
将数据传递给它,但我们如何将数据发送回父级?
我能看到的文档中没有显示正在发回的数据。
this.dialogService.open(SomeModalComponent, {
...
data: {
someData: 'some string'
},
}
在对话框中,我们使用数据
ngOnInit(): void {
console.log(this.config?.data?.someData); // 'some string'
}
- 在父组件
ref: DynamicDialogRef;
中添加ref - 在组件提供程序中添加
DialogService
- 打开对话框:
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
});
- 在对话框组件
public ref: DynamicDialogRef
中注入DynamicDialogRef
- 在对话框组件中,使用
close()
函数发回数据:this.ref.close(this.uploadedFiles)
- 在父组件中
this.ref.onClose.subscribe((files: customUploadFile[]) => {
// put your code here
});