2017-01-21 8 views
1

thisを使用して私のウェブサイトを作成し、$ rootScope.on( '$ stateChangeStart')を使ってrunメソッドを作成していて動作していません。私は、ウェブサイトが機能しているが、第2の2件のログがありません問題がある任意のアイデアを読み込むとき

.run('Url',function($rootScope, $state, $location){ 
    'ngInject' ; 

    console.log('Is working'); 
    function message(to, toP, from, fromP) { 
     return from.name + angular.toJson(fromP) + " -> " + to.name + angular.toJson(toP); 
    } 
    $rootScope.$on("$stateChangeStart", function(evt, to, toP, from, fromP)  { 
     console.log("Start: " + message(to, toP, from, fromP)); 
     console.log('Not working'); 
    }); 

まずログ:ここでは、コードのですか?

答えて

0

あなたはrootScopeを使用することができます$のよう

.run(['$rootScope', '$state', '$location',function($rootScope, $state, $location){ 
     console.log('Is working'); 
     function message(to, toP, from, fromP) { 
      return from.name + angular.toJson(fromP) + " -> " + to.name + angular.toJson(toP); 
     } 
     $rootScope.$on("$stateChangeStart", function(evt, to, toP, from, fromP)  { 
      console.log("Start: " + message(to, toP, from, fromP)); 
      console.log('Not working'); 
     }) 
    }]); 
+0

にそれでも、他の提案を働いていないの負荷を追加しますか? – Wolffyx

0

としてこれを試してください:あなたは、バージョンを変更した場合は

$rootScope.$on('$viewContentLoading', function() { 
    // your stuff here… 
}); 
$rootScope.$on('$viewContentLoaded', function() { 
    // your stuff here… 
}); 
0

: '$ viewContentLoading' または '$ viewContentLoaded'。

新しいui-router(Angular 1.xバージョン)用。あなたはstateEventsファイルをロードする必要があります。

<script src="lib/angular-ui-router/release/stateEvents.min.js"></script> 

それはあなたのアプリケーション

angular.module('MyApp', ['ui.router', 'ui.router.state.events', ... 
関連する問題