Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

routeChangeStart is not fired when route changed

I have this code snippet below (ionic framework) but routeChangeStart is not printed when i'm navigating around.

.run(function($ionicPlatform, $rootScope, $location) {
  $ionicPlatform.ready(function() {
    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if (window.StatusBar) {
      StatusBar.styleDefault();
    }
  });

  $rootScope.$on('$routeChangeStart', function(event, next, current) {
    console.info('[event] routeChangeStart...');
  });
})
like image 786
Tuan Anh Tran Avatar asked Jan 13 '15 07:01

Tuan Anh Tran


1 Answers

I believe that ionic framework is using ui-router instead of ngRoute..So change your code as follows and try...

$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){
  //print here
});

please look the following link for the difference between those router modules http://www.amasik.com/angularjs-ngroute-vs-ui-router/

like image 84
Asik Avatar answered Oct 12 '22 00:10

Asik