用 1.0.0 替换 ui 路由器 0.2 [英] Replacing ui router 0.2 with 1.0.0
问题描述
我已将 ui-router v0.2 升级到 1.0.0,但我的现有代码存在一些问题.所以我在官方文档中读到
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'
现在替换为 $transitions.onStart({},
同 $rootScope.$on('$stateChangeSuccess'
和 $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);
}
我尝试了以下方法:
$transitions.onStart({}, function (toState, toParams) {
$state.go(toState, toParams);
}
但是 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.
推荐答案
文档位于:http://angular-ui.github.io/ui-router/feature-1.0/ 你可以为这样的特定场景设置特定的回调:
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();
});
这篇关于用 1.0.0 替换 ui 路由器 0.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!