Issue
I have a following dialog component (which I open using dialog.open(MyDialogComponent) in another component):
export class MyDialogComponent implements OnInit {
constructor(public matDialogRef: MatDialogRef<MyDialogComponent>) {}
ngOnInit() {}
}
I know I can return any data to the calling component by executing matDialogRef.close(dataToReturn) bound to a button in dialog component. But how can I return the data if a user clicked elsewhere but the popup to close it?
Solution
If anybody is interested I found a solution (not sure if it is the best one). Just disabling the default close operation so the popup does not close on backround click, while closing it with data param on background click.
matDialogRef.disableClose = true;//disable default close operation
matDialogRef.backdropClick().subscribe(result => {
matDialogRef.close(dataToReturn);
});
This way the calling component receives the data whether the dialog was closed by button or clicked elsewhere.
Answered By - Matúลก Zábojník
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.