Cdk DialogRef.afterClosed is called twice
See original GitHub issueBug, feature request, or proposal:
const dialogRef = this.dialog.openFromComponent(FooComponent);
dialogRef.afterClosed().subscribe(() => console.log('close'));
The above code logs “close” twice. From debugging i can see that the _onAnimationDone
callback in cdk-dialog-container.ts is called twice.
What is the expected behavior?
It should emit an afterClosed once.
What is the current behavior?
Emits afterClosed twice.
What are the steps to reproduce?
https://angular-material2-issue-s2bybt.stackblitz.io
What is the use-case or motivation for changing an existing behavior?
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
6.0.*
Is there anything else we should know?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Unable to pass data in Material Dialog in Angular Material
this.dialogRef.close(this.data);. afterClosed() should be subscribed to so that a handler is called when the dialog is closed.
Read more >Routing to Angular Material Dialogs | by John Crowson | ngconf
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, { width: '250px', ... Navigate back to the parent in the MatDialog afterClosed subscription:
Read more >angular/angular - Gitter
AdmindashboardComponent is the component youre calling the dialog right? ... export class DialogOverviewExampleDialog { constructor( public dialogRef: ...
Read more >Easy Angular Testing – UI Elements – Dialog - Coder.Haus
The Ok button closes the dialog and sends data back to our calling method via the mat-dialog-close attribute and its bound value.
Read more >Dialog | Angular Material
afterClosed ().subscribe(result => { console.log(`Dialog result: ${result}`); // Pizza! }); dialogRef.close('Pizza!'); Components created via MatDialog can ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks, this patched an issue we were seeing with Microsoft Edge
Workaround for now:
dialogRef.afterClosed().pipe(take(1)).subscribe(...)