119
rated 0 times
[
126]
[
7]
/ answers: 1 / hits: 99586
/ 11 Years ago, thu, may 2, 2013, 12:00:00
How do I cancel route change event in AngularJs?
My current code is
$rootScope.$on($routeChangeStart, function (event, next, current) {
// do some validation checks
if(validation checks fails){
console.log(validation failed);
window.history.back(); // Cancel Route Change and stay on current page
}
});
with this even if the validation fails Angular pulls the next template and associated data and then immediately switches back to previous view/route. I don't want angular to pull next template & data if validation fails, ideally there should be no window.history.back(). I even tried event.preventDefault() but no use.
More From » angularjs