My code using the $location service in angular seems to be malfunctioning.
angular.module("app",[]).run(function($rootScope) {
var $offFunction = $rootScope.$on("$locationChangeStart", function(e) {
if (confirm("Are you sure"))
return $offFunction();
return e.preventDefault();
});
});
I am trying to prompt the user to confirm if they want to leave the page, but it does not work when changing the address in the bar or clicking the back button in the browser.
Here is the code on fiddler: http://jsfiddle.net/5dnm2/19/