you can prevent to close dialog
from click outside
or esc
using disableClose: true
let dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: { name: this.name, animal: this.animal },
scrollStrategy: this.overlay.scrollStrategies.close(),
disableClose: true //for diabled close dialog
});
You can use confirmation
dialog with below code :
onNoClick(): void {
var cn = confirm('You have begun editing fields for this user. Do you want to leave without finishing?');
console.log(cn);
if(cn){
this.dialogRef.close();
}
};
onOKClick(): void {
var cn = confirm('You have begun editing fields for this user. Do you want to leave without finishing?');
console.log(cn);
if(cn){
this.dialogRef.close();
}
};
HTML Code :
<div mat-dialog-actions>
<button mat-button (click)="onNoClick()">No Thanks</button>
<button mat-button (click)="onOKClick()" cdkFocusInitial>Ok</button>
</div>
reference Link: link1, link2