Replacing ui router 0.2 with 1.0.0

泪湿孤枕 提交于 2019-12-23 01:54:27

问题


I have upgraded ui-router v0.2 to 1.0.0 but I have some issues with my existing code. So I read in the official docs that

$rootScope.$on('$stateChangeStart'

is now replaced with $transitions.onStart({},

same with $rootScope.$on('$stateChangeSuccess' with $transitions.onSuccess({},

So far so good. But in my original code I have the following:

$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
   // some code here
   $state.go(toState.name, toParams);
}

I tried the following:

$transitions.onStart({}, function (toState, toParams) { 
     $state.go(toState, toParams);
}

But toState and toParams are not available ... I looked at the docs but cannot really figure out what should I do here. Any help will be greatly appreciated. Thanks.


回答1:


The documentation is located here: http://angular-ui.github.io/ui-router/feature-1.0/ You can setup specific callbacks for specific scenarios like this:

$transitionsProvider.onBefore({ to: 'my.state', from: '*' }, function(AsyncService) {
  return AsyncService.doSomeAsyncThing();
});


来源:https://stackoverflow.com/questions/37786841/replacing-ui-router-0-2-with-1-0-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!