Bug MatDialog is unclosable
See original GitHub issueBug, feature request, or proposal:
Bug
What is the expected behavior?
Should be able to close dialog
What is the current behavior?
Cannot close dialog - for a predictable/certain code path
What are the steps to reproduce?
Here is the problem: https://www.useloom.com/share/7eb9c523ee3144fb94bb2b49b57dee1b
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular5, Material2, MacOS, tsc version 2.6.1
More info
in both cases, the dialog is created using the same code, here is the code to create dialog:
'use strict';
import {Component, OnInit, Inject, Injectable} from '@angular/core';
import {MainDataService} from '../../services/main';
import {MAT_DIALOG_DATA, MatDialogRef, MatDialogConfig} from '@angular/material';
import {MatDialog} from '@angular/material/dialog';
@Component({
templateUrl: './stop-recording-dialog.component.html',
styleUrls: ['./stop-recording-dialog.component.scss']
})
export class StopRecordingDialogComponent implements OnInit {
public dialogResult: any;
escapeToClose = true;
constructor(public dialogRef: MatDialogRef<StopRecordingDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: string,
private mds: MainDataService) {
}
onClickClose() {
this.dialogRef.close();
this.mds.dialogEmitter.emit({
name: 'stop-recording-run-dialog-closed',
value: 'x'
});
}
}
@Injectable()
export class StopRecordingDialog {
escapeToClose = true;
dialogRef: MatDialogRef<StopRecordingDialogComponent> | null;
config = Object.assign(new MatDialogConfig(), {
width: '600px',
data: 'This text is passed into the dialog!'
});
constructor(public dialog: MatDialog, private mds: MainDataService) {}
openDialog() {
this.dialogRef = this.dialog.open(StopRecordingDialogComponent, this.config);
this.dialogRef.beforeClose().subscribe((result: string) => {
console.log(`Dialog before closed: ${result}`);
});
this.dialogRef.afterClosed().subscribe(result => {
console.log(`Dialog after closed: ${result}`);
});
}
}
even when it fails to close, the onClickClose()
method is called, so not sure why the dialog won’t close.
Issue Analytics
- State:
- Created 6 years ago
- Comments:17 (15 by maintainers)
Top Results From Across the Web
MatDialog dialog from Angular Material is not closing
If you have an error occurring in the ngOnChanges of another component it can cause this un-closable dialog behavior.
Read more >How to use Mat-Dialog in Angular ? - GeeksforGeeks
First we need to import 'MatDialog' from '@angular/material/dialog' and we need to create an instance for it in the constructor.
Read more >Disable click outside of angular material dialog area to close ...
In the method that opens the dialog, pass in the following configuration option disableClose as the second parameter in MatDialog#open() and set it...
Read more >Dialog | Angular Material
The MatDialog service can be used to open modal dialogs with Material Design styling and animations. Dialog Overview.
Read more >Angular Material Dialog: A Complete Example
In this post, we are going to go through a complete example of how to build a custom dialog using the Angular Material...
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
Closing since this does sound like an issue with escaping the Angular zone. You can re-enter the zone by injecting
NgZone
and doing@ORESoftware I actually don’t have any Angular 1 experience, so I dunno. The root of this issue is that your browser extension callback is not executing within the NgZone. You can probably pull the
ngZone.run()
part intothis.mds
so that it’s consolidated better and not left to your dialog service to handle.It’s a common issue when incorporating 3rd party libs/apis.