javascript - AngularJs - cancel route change event -


how cancel route change event in angularjs?

my current code is

$rootscope.$on("$routechangestart", function (event, next, current) {  // validation checks if(validation checks fails){      console.log("validation failed");      window.history.back(); // cancel route change , stay on current page    } }); 

with if validation fails angular pulls next template , associated data , switches previous view/route. don't want angular pull next template & data if validation fails, ideally there should no window.history.back(). tried event.preventdefault() no use.

instead of $routechangestart use $locationchangestart

here's discussion angularjs guys: https://github.com/angular/angular.js/issues/2109

example:

$scope.$on('$locationchangestart', function(event) {     if ($scope.form.$invalid) {        event.preventdefault();     } }); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -