问题
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