angular的$rootScope.$on方法

angular项目需要监听路由所以$rootScope.$on(…….)就变得尤为重要;

$rootScope.$on(…….)里面接受两个参数,第一个为函数名称,第二个为回调函数:

如$rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){});
也可以这样写$rootScope.$on('$stateChangeStart', stateChangeStart);
function stateChangeStart(event, toState, toParams, fromState, fromParams){};
回调函数内的参数:
  • event:当前事件信息;
  • toState:转跳目标路由信息;
  • toParams:传递到目的路由的参数;
  • formState:路由器是起始状态;
  • formPaeams:剩余参数;

$stateChangeStart: 表示状态切换开始;

$stateNoFound:没有发现;

$stateChangeSuccess:切换成功;

$stateChangeError:切换失败;

以此监听路由的动态。

猜你喜欢

转载自www.cnblogs.com/cx19950223/p/11051379.html