javascript - On location change in Angular -
is there way detect global location changes in angularjs, not single controller? goal detect every location change. or there effective way watch window.location.href changes?
$routechangesuccess as understood single controller or i'm wrong?
first of all, $routechangesuccess not limited single controller. broadcast $rootscope means can listened on every scope (or, every scope inherits $rootscope) application wide event.
there undocumented event works similar $routechangesuccess called $locationchangesuccess. difference former fires once route has changed , latter fires when url changed before route changes. note isn't url changes, times url changes in way angularjs application can register (for example, setter call $location.url()).
just clarify, $locationchangesuccess broadcast $rootscope well.
for both, can listen event using scope.$on('$routechangesuccess') or scope.$on('$locationchangesuccess').
Comments
Post a Comment