Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Created December 13, 2017 17:47
Show Gist options
  • Save brachi-wernick/7d26270645e9ed4d66b2c13ccc1252af to your computer and use it in GitHub Desktop.
Save brachi-wernick/7d26270645e9ed4d66b2c13ccc1252af to your computer and use it in GitHub Desktop.
CanDeactivateGuard deneric
@Injectable()
export class CanDeactivateGuard implements CanDeactivate<ComponentCanDeactivate> {
canDeactivate(component: ComponentCanDeactivate): boolean {
if(!component.canDeactivate()){
if (confirm("You have unsaved changes! If you leave, your changes will be lost.")) {
return true;
} else {
return false;
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment