首页 > 解决方案 > Primeng - 对话服务将数据传递给对话组件

问题描述

使用 PrimeNg 的动态对话示例展示了目标对话如何获取数据并显示。我可以通过创建一个带有可观察对象的服务来将数据传递给对话,但我知道对话服务有一些可用的参数(如数据)可以传递。对话将如何检索通过服务传递的数据?

https://www.primefaces.org/primeng/#/dynamicdialog https://github.com/primefaces/primeng/blob/master/src/app/components/dynamicdialog/dynamicdialog-config.ts https://github。 com/primefaces/primeng/blob/master/src/app/components/dynamicdialog/dialogservice.ts

标签: typescriptcomponentsobservableprimeng

解决方案


内部父组件:

this.dynamicDialogRef = this.dialogService.open(EmployeeDialogComponent, {
    header: 'View Employee Details for - ' + this.employee.name,
    width: '90%',
    contentStyle: {"min-height": "800px", "overflow": "auto"},
    baseZIndex: 10000,
    data: {employee: this.employee}
});

内部对话框组件:

export class EmployeeDialogComponent implements OnInit {
constructor(public ref: DynamicDialogRef, public config: DynamicDialogConfig) { 
     console.log("Data: " + JSON.stringify(config.data.employee));
}
ngOnInit() {}
}

推荐阅读