javascript - AngularJS $locationChangeStart never called -
i have simple code using $location service in angular not work.
angular.module("app",[]).run(function($rootscope) { var $offfunction = $rootscope.$on("$locationchangestart", function(e) { if (confirm("are sure")) return $offfunction(); return e.preventdefault(); }); });
i want confirm if user wants leave page, won't work if try change address in bar or if press button in browser.
here fiddler: http://jsfiddle.net/5dnm2/19/
you have add $location initialization provider. visit http://jsfiddle.net/5dnm2/41/ run(function($rootscope, $location) {...})
Comments
Post a Comment