Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Created December 13, 2017 17:43
Show Gist options
  • Save brachi-wernick/3fac8ae8ceb6d44d12ab37a077c79545 to your computer and use it in GitHub Desktop.
Save brachi-wernick/3fac8ae8ceb6d44d12ab37a077c79545 to your computer and use it in GitHub Desktop.
ComponentCanDeactivate generic class to handle can deactivate
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