My Angular app creates a modal dialog to allow user to input and change some properties. It is requested to warn user that there is unsaved changes in the model when user tries to cancel the modal (click X, or click outside of the modal).
const modal = this.modalService.create({
nzTitle: title,
nzContent: MyModalComponent,
nzComponentParams: {
// component parameters
},
nzFooter: null,
nzOnCancel: (result) => {
if (result changed) {
return;
} else {
return new Promise((resolve, reject) => {
this.modalService.confirm({
nzTitle: `If you leave, your unsaved changes will be lost. Do you want to leave?`,
nzOkText: 'Yes',
nzOkType: 'danger',
nzOnOk: () => resolve(true),
nzCancelText: 'No',
nzOnCancel: () => resolve(false),
});
}).catch(() => console.log('cancel'))
}
}
});
In the above code, the "result" does not reflect the changes in the modal, therefore it does not work.
What is the best way of achieving it?