Created
June 20, 2019 14:54
-
-
Save romanoffs/302c01274fdfb1a53ce8f429de905796 to your computer and use it in GitHub Desktop.
Angular 7 ComponentCanDeactivate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {HostListener} from '@angular/core'; | |
import {Observable} from 'rxjs'; | |
export abstract class ComponentCanDeactivate { | |
abstract get saved(): boolean; | |
abstract canDeactivate(): Observable<boolean> | Promise<boolean> | boolean | |
@HostListener('window:beforeunload', ['$event']) | |
unloadNotification($event: any): void { | |
if (!this.saved) { | |
$event.returnValue = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment