Skip to content

Instantly share code, notes, and snippets.

@richmwatts
Created August 5, 2014 08:54
Show Gist options
  • Save richmwatts/7f3dd530087378759992 to your computer and use it in GitHub Desktop.
Save richmwatts/7f3dd530087378759992 to your computer and use it in GitHub Desktop.
$scope.detachLocationChangeListener = $scope.$on('$locationChangeStart', function (event, next, current) {
event.preventDefault(); //prevent the navigation
$scope.showSaveChangesDialog = true; //dialog control
$scope.nextRoute = $location.url(next).hash(); //grab requested location
});
$scope.confirmSaveChanges = function (answer) {
if (answer == true) {
alert("clicked yes, save changes");
}
else{
alert("clicked no, discard changes");
}
$scope.detachLocationChangeListener();
$location.path($scope.nextRoute); //regardless the action we want to navigate to the request location
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment