0

I'm watching the $locationChangeSuccess event. I need a clean way to check whether the URL has changed or if only the parameters have changed. I could compare the 'next' and 'current' parameters, but maybe there's a function doing that already ?

Mark Coleman
  • 40,542
  • 9
  • 81
  • 101
Sam
  • 13,934
  • 26
  • 108
  • 194

1 Answers1

0

Set up a custom watch:

function MyCtrl($scope, $location) {
  // Watch parameters...
  $scope.$watch(function() {
    return $location.search();
  }, function(newParams, oldParams) {
    console.log(newParams);
    console.log(oldParams);
  }, true);
}

Note the third argument true passed to $scope.$watch(); important to ensure the watch value, in this case an object, is watched deeply for changes (and not referentially).

Ezekiel Victor
  • 3,877
  • 1
  • 27
  • 28