gpt4 book ai didi

javascript - 如何使用 $transitions?

转载 作者:可可西里 更新时间:2023-11-01 02:18:23 25 4
gpt4 key购买 nike

目前,我正在使用:

  • “Angular 用户界面路由器”:“^0.4.2”
  • “Angular ”:“^1.6.3”
  • "webpack": "^2.4.1"

我知道我当前的实现可能是 deprecated ,只是寻找新方法的实现(示例或文档)。非常感谢任何帮助,提前致谢!

当前实现:

'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);
});

当前错误:

Uncaught Error: [$injector:unpr] Unknown provider: $transitionsProvider <- $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());
});
}

按调用排序的可用事件:

$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 service docs
还有一些例子:Migrations examples from 0.4.2 to 1.0.0 in official docs


旧版本 (<= 0.4.2) 的 $state 更改事件 ( PLUNKER DEMO ):

MyCtrl.$inject = ['$scope'];

function MyCtrl($scope) {
$scope.$on('$stateChangeStart',
function(event, toState, toParams, fromState, fromParams, options) {...});

$scope.$on('$stateChangeSuccess',
function(event, toState, toParams, fromState, fromParams, options){...});
}

检查 angular-ui-router docs了解更多 $state 变化事件

关于javascript - 如何使用 $transitions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43746989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com