Events exist, for some reason they are undocumented.
Try the following events: $locationChangeStartand$locationChangeSuccess
scope.$on('$locationChangeStart', function (event, newLoc, oldLoc){
console.log('changing to: ' + newLoc);
});
scope.$on('$locationChangeSuccess', function (event, newLoc, oldLoc){
console.log('changed to: ' + newLoc);
});
Or you can $ watch any value you want by passing the function to the first argument of $ watch, as Anders suggested:
scope.$watch(function() { return $location.path(); }, function(newLoc, oldLoc){
console.log(newLoc, oldLoc);
});
However, this will create a bit more overhead on your $ digest.
source
share