2

I have an mat dialog component in my project as I press Confirm button I call

  onCloseConfirm(data) {
    this.thisDialogRef.close('Confirm');
    console.log("conf data", data);
  }

in my parent I subscribe to passed data (in my Case 'Confirm');

   dialogRef.afterClosed().subscribe(result => {
      console.log(`Dialog closed: ${result}`);
});

What I would like to do is to pass data also. So I would like to pass the 'Confrim' message + data both. Is it possible?

Anna F
  • 1,583
  • 4
  • 22
  • 42

1 Answers1

4

You can pass anything to the close method, so you could pass something like this:

 onCloseConfirm(data) {
    this.thisDialogRef.close({
       message: 'Confirm',
       data
    });
    console.log("conf data", data);
  }

And then, in the afterClosed handler:

dialogRef.afterClosed().subscribe(result => {
  console.log(`Dialog closed: ${result.message}`, result.data);
});
n.yakovenko
  • 1,957
  • 1
  • 16
  • 15
Thor Jacobsen
  • 8,621
  • 2
  • 27
  • 26