I have declared $rootScope.$on function under the myApp.run to check token value in every authenticated page.but its not working.I do not understand why its not working.Please help me.
app.js
myApp.run(['$rootScope','$state', '$location', 'loginService', function ($rootScope,$state, $location, loginService) {
console.log(" under run => ");
$rootScope.$on('routeChangeStart', function (event, next, current) {
/*If route is authenticated then check if the user has access token, else return to login screen*/
console.log(event);
if (next.$$route.authenticated) {
var userAuth = loginService.getUserToken();
console.log(" usertoken => " +userAuth);
if (!userAuth) {
$location.path("/");
}
}
});
}]);
code print on console "under run =>" but it is not printing event object and also not check if condition.