In certain scenarios, you have the option to start with setting disableClose
as false
, allowing the user to close it if there are no pending changes. However, depending on the nature of the pending change (such as an asynchronous call), you may need to switch disableClose
to true
.
Another approach is to inject the MatDialogRef
directly into the component and manually control disableClose
based on your specific requirements, like so:
constructor(private matDialogRef: MatDialogRef<WhateverYourDialogIsCalled>) {}
Then, in the case of an asynchronous call, you could do something like this:
onSubmit() {
this.matDialogRef.disableClose = true;
this.myService.doSomething().subscribe(_ => {
this.matDialogRef.disableClose = false;
});
}