2017-01-21 4 views
1

Я использую this для создания своего сайта и когда я создал метод запуска с $ rootScope.on ('$ stateChangeStart') в нем и не работает. Вот код:

.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

Попробуйте с этим:. '$ ViewContentLoading' или '$ viewContentLoaded':

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

При изменении версии.

Для нового ui-router (Угловая версия 1.x). Вам нужно загрузить файл stateEvents.

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

добавить загрузите его в приложении

angular.module('MyApp', ['ui.router', 'ui.router.state.events', ...