如何监视/触发路线上的事件?
注意:这是AngularJS的旧版本的正确答案。有关更新版本,请参阅this question。
$scope.$on('$routeChangeStart',function(next,current) { ... you could trigger something here ... });
以下事件也可用(它们的回调函数采用不同的参数):
> $ routeChangeSuccess
> $ routeChangeError
> $ routeUpdate – 如果reloadOnSearch属性设置为false
请参阅$route文档。
还有两个其他undocumented事件:
> $ locationChangeStart
> $ locationChangeSuccess
见What’s the difference between $locationChangeSuccess and $locationChangeStart?