Amit Thakkar
Amit Thakkar

Reputation: 787

$routeChangeSuccess is not working with ngNewRouter AngularJS 1.4

I am moving from AngularJS 1.3 to AngularJS 1.4. And this time I am using AngularJS new route e.g. ngNewRouter which is introduced in AngularJS 1.4.

My sample code is as below:

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 is working fine but $routeChangeSuccess is not getting called ever :( .

Might be $routeChangeSuccess lister will be called with ngRoute module only, and I am using ngNewRouter instead of ngRoute. If its true then which lister should I bind in place of $routeChangeSuccess ?

Upvotes: 6

Views: 729

Answers (1)

Shreyance Jain
Shreyance Jain

Reputation: 944

There are some Hooks available for change detection. I think you should listen activate hook on controller where you want to detect change. You can look here for more detail.

Upvotes: 2

Related Questions