如何使用$ transitions? [英] How to use $transitions?
问题描述
当前,我正在使用:
- "angular-ui-router":"^ 0.4.2"
- 角度":"^ 1.6.3"
- "webpack":"^ 2.4.1"
我知道我当前的实现可能已弃用,仅查找新方法的实现(示例或文档).非常感谢您的帮助,在此先感谢!
I am aware of my current implementation might be deprecated, just looking for the implementation(an example or documentation) of the new method. Any help is greatly appreciated, thanks in advance!
当前实施:
'use strict';
module.exports = angular
.module('common', [
'ui.router',
'angular-loading-bar',
require('./header').name,
require('./sideBar').name,
require('./footer').name
])
.run(function($transitions, cfpLoadingBar) {
$transitions.onStart({}, cfpLoadingBar.start);
$transitions.onSuccess({}, cfpLoadingBar.complete);
});
当前错误:
未捕获的错误:[$ injector:unpr]未知提供程序:$ transitionsProvider<-$ transitions
Uncaught Error: [$injector:unpr] Unknown provider: $transitionsProvider <- $transitions
推荐答案
在新版本(> = 1.0.0)中,不建议使用$ state更改事件,现在 您必须改用
$transitions
...
In new versions (>=1.0.0) the $state change events are deprecated, and now you have to use the
$transitions
instead...
新版本的$ transitions(> = 1.0.0)( PLUNKER DEMO )
MyCtrl.$inject = ['$transitions'];
function MyCtrl($transitions) {
$transitions.onSuccess({}, function($transition){
console.log($transition.$from());
console.log($transition.$to());
console.log($transition.params());
});
}
通过调用排序的可用事件:
Available events ordered by invocation:
$transitions.onStart({}, function($transition){...});
$transitions.onExit({exiting: "stateName"}, function($transition){...});
$transitions.onRetain({}, function($transition){...});
$transitions.onEnter({entering: "stateName"}, function($transition){...});
$transitions.onFinish({}, function($transition){...});
$transitions.onSuccess({}, function($transition){...});
也详细了解了每个事件方法: $ transition服务文档
还有一些示例:来自0.4的迁移示例官方文档中的.2到1.0.0
Too see each event method in detail: $transition service docs
Also some examples: Migrations examples from 0.4.2 to 1.0.0 in official docs
$ state更改旧版本(< = 0.4.2)的事件( 检查 angular-ui-router文档更多$ state更改事件
Check angular-ui-router docs for more $state change events
这篇关于如何使用$ transitions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!