How Can I close the dialog in this stackblitz example (Minimal, Reproducible Example.) by clicking outside ?
This works fine if I remove the property hasBackdrop: false
-> Working Stackblitz Example
The standard approach for creating an Angular Material Dialog that closes when clicking outside the dialog box (while creating the appearance that there is no backdrop) is to use the built-in library CSS class cdk-overlay-transparent-backdrop
and apply it using the MatDialogConfig
property backdropClass
.
The openDialog
method would be:
openDialog(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
backdropClass: 'cdk-overlay-transparent-backdrop',
hasBackdrop: true,
width: '250px'
});
}
See Stackblitz Example
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