Skip to content

Instantly share code, notes, and snippets.

@Kasahs
Created March 14, 2016 11:03
Show Gist options
  • Save Kasahs/aad942c8c9ab0c14e384 to your computer and use it in GitHub Desktop.
Save Kasahs/aad942c8c9ab0c14e384 to your computer and use it in GitHub Desktop.
Angular page unload prevention dialog
vm.unloadWatcher = $scope.$on('$locationChangeStart', function(event, next, current) {
if(!confirm("Are you sure you want to leave this page?")) {
event.preventDefault();
}
});
$scope.$on('$destroy', function(){
vm.unloadWatcher();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment