Created
March 14, 2016 11:03
-
-
Save Kasahs/aad942c8c9ab0c14e384 to your computer and use it in GitHub Desktop.
Angular page unload prevention dialog
This file contains 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
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