Created
December 13, 2017 17:43
-
-
Save brachi-wernick/3fac8ae8ceb6d44d12ab37a077c79545 to your computer and use it in GitHub Desktop.
ComponentCanDeactivate generic class to handle can deactivate
This file contains hidden or 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"; | |
export abstract class ComponentCanDeactivate { | |
abstract canDeactivate(): boolean; | |
@HostListener('window:beforeunload', ['$event']) | |
unloadNotification($event: any) { | |
if (!this.canDeactivate()) { | |
$event.returnValue =true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment