You can add disableClose: true
to the dialogRef
configuration, to prevent the dialog closing from pressing esc. It's explained in the API of the Dialog component.
disableClose: boolean
Whether the user can use escape or clicking on the backdrop to close the modal.
openDialog(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: {name: this.name, animal: this.animal},
disableClose: true
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
See this updated StackBlitz for reference.