本文介绍了如何在AngularJS中观察路线变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在路线上观察/触发事件?
How would one watch/trigger an event on a route change?
推荐答案
注意:对于AngularJS的旧版本,这是一个正确的答案。有关更新版本,请参见。
Note: This is a proper answer for a legacy version of AngularJS. See this question for updated versions.
$scope.$on('$routeChangeStart', function($event, next, current) {
// ... you could trigger something here ...
});
以下事件也可用(它们的回调函数采用不同的参数):
The following events are also available (their callback functions take different arguments):
- $ routeChangeSuccess
- $ routeChangeError
- $ routeUpdate - if 属性设置为false
- $routeChangeSuccess
- $routeChangeError
- $routeUpdate - if reloadOnSearch property has been set to false
参见 docs。
还有另外两个事件:
- $ locationChangeStart
- $ locationChangeSuccess
See What's the difference between $locationChangeSuccess and $locationChangeStart?
这篇关于如何在AngularJS中观察路线变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!