$ routeChangeSuccess does not work with ngNewRouter AngularJS 1.4

I am moving from AngularJS 1.3 to AngularJS 1.4 . And this time I'm using the new AngularJS new route, for example. ngNewRouter , which is introduced in AngularJS 1.4 .

My sample code is as follows:

 var versionModule = ng.module('test', ['ngNewRouter']); versionModule.controller('TestController', ['$rootScope', '$router', function ($rootScope, $router) { var version = this; $router.config([ { path: '/', redirectTo: '/home' }, { path: '/home', component: 'home' } ]); $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { console.log("This line is not getting printed ever."); }); }]); 

Routing works fine, but $ routeChangeSuccess is never called :(.

Maybe the $ routeChangeSuccess lister will only be called with the ngRoute module, and I use ngNewRouter instead of ngRoute . If its true, then which lister should I bind instead of $ routeChangeSuccess ?

+6
source share
1 answer

Several hooks are available to detect changes. I think you should listen for hook activation on the controller where you want to detect changes. You can look here for more details.

+2
source

All Articles