Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$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 ?

like image 470
Amit Thakkar Avatar asked Jul 24 '15 09:07

Amit Thakkar


1 Answers

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.

like image 96
Shreyance Jain Avatar answered Nov 08 '22 19:11

Shreyance Jain