I have a canDeactivate method that alert user to save changes before leave the page:
@HostListener('window:beforeunload')
canDeactivate(): Observable<boolean> | boolean {
return !hasChangesOnMyList();
}
I want to remove this alert when user do a specific task. I tried something like this:
window.addEventListener("beforeunload", (event) => {
event.stopImmediatePropagation();
}, true);
But this is not working. I also tried this, without success.
window.removeEventListener('beforeunload', this.canDeactivate, true);
How can I do that?