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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -