2017-05-02 6 views
6

現在、私が使用している:

  • "角度-UI-ルータを": "^ 0.4.2"
  • を "角度": "^ 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

+0

常に '$ inject'または配列notatianを使用して手動で注入を指定します。 –

+0

@AluanHaddad、それはそれほど簡単だったと思う。それは依存の注入ではありません。 – alphapilgrim

+1

あなたが知らなかった場合にだけ言及してください。 –

答えて

8

In new versions (>=1.0.0) the $state change events are deprecated, and now you have to use the $transitions instead...

$遷移(> = 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()); 
    }); 
} 
0呼び出し順の

利用可能なイベント:

$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 docs
はまた、いくつかの例:Migrations examples from 0.4.2 to 1.0.0 in official docs


$の状態は、イベントを変更します古いバージョン(012 = 0.4.)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