I am using MatDialogRef in order to invoke a Modal from a component.
When closing the ModalComponent, I try to get back data, but nothing seems to pass back.
dialogRef = dialog.open(ModalComponent,ConfigObj).afterClosed
.subscribe(data => console.log(data));
All other features of the Modal including passing data from the baseComponent to the ModalComponent seem to be working fine.
Old question, but in case anyone else stumbles across this:
DialogRef will return the data you pass in when you call dialogRef.close(). When you're done in your Dialog Component, call:
const myDataObject = {
field1: 'My field'
}
dialogRef.close(myDataObject);
Then in your parent component, subscribe to the data with:
dialogRef.afterClosed()
.subscribe( data => console.log(myDataObject.field1));
This will log 'My field'.
The return value of the modal isn't the 'data' object you pass in, it's just whatever you want to return.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With