Search code examples
typescriptcomponentsobservableprimeng

Primeng - dialog service passing data to dialog component


Using PrimeNg's dynamic dialogue example shows how the destination dialogue can get data and display. I can go through creating a service with observables to pass the data to the dialogue, but I know there are some arguments available to the dialogue service (like data) that can be passed through. How would the dialogue retrieve the data passed through the service?

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


Solution

  • The dynamic dialog has an option in the constructor to pass data. example,

    const ref = this.dialogService.open(MyComponent, {data : myData});

    UPDATE

    you should inject DynamicDialogService on your constructor and then you can access data which you passed on your dialog

    code is here :

    constructor( private dialogService: DynamicDialogService) {}
    

    and then you can access and see all data you passed like this:

    console.log(this.dialogSerive.data)