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 ?
Asked
Active
Viewed 705 times
0

Mark Coleman
- 40,542
- 9
- 81
- 101

Sam
- 13,934
- 26
- 108
- 194
-
i think there is not existing function to do such comparison – Ajay Beniwal May 02 '13 at 12:55
1 Answers
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