1

I am looking for a way to know the source of the event in angularjs routing. Here is the scenario I am trying to solve. When url changes I want to know whether the change was caused by a browser back button or not. I thought I can do like this

$scope.$on('$routeUpdate', function (event) { 
    //if source is back button do this stuff
    // if not do this
});

But the event object doesn't have a source information. Did I miss something here? Is there a better way to do it?

yesIcan
  • 1,441
  • 1
  • 11
  • 18

1 Answers1

2

Instead of $routeUpdate use '$locationChangeStart'

Here's the discussion about it from the angularjs guys: https://github.com/angular/angular.js/issues/2109

Example:

$scope.$on('$locationChangeStart', function(event) {
if ($scope.form.$invalid) {
   event.preventDefault();
  }
});
GANI
  • 2,013
  • 4
  • 35
  • 69
  • check this too http://stackoverflow.com/questions/14765719/how-to-watch-for-a-route-change-in-angularjs – GANI Jun 03 '15 at 17:30