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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With