Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Last active December 13, 2017 17:37
Show Gist options
  • Save brachi-wernick/57897484eaf2d8b57e0b4883e5f47535 to your computer and use it in GitHub Desktop.
Save brachi-wernick/57897484eaf2d8b57e0b4883e5f47535 to your computer and use it in GitHub Desktop.
canDeactivateGuard-ng5
@Injectable()
export class CanDeactivateGuard implements CanDeactivate<UserFormComponent> {
canDeactivate(component: UserFormComponent): boolean {
if(component.hasUnsavedData()){
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