The situation is that, I have "routeChangeSuccess" event at (run). That event change the value of $rootScope.authenticated based on the REST request response status code.
But when the event is triggered and I try to print to the console the value of $rootScope.authenticated in one of my controllers, it says it is "undefined" value.
Angular run:
pos.run(function($rootScope,$log,apiService){
// register event
$rootScope.$on('$routeChangeSuccess', function () {
// call api function
apiService.is_authenticated().then(
function(response){
if(response.status == "AUTHENTICATED"){
$rootScope.authenticated = true;
}else if(response.status == "NOT_AUTHENTICATED"){
$rootScope.authenticated = false;
}
});
})
});
The controller:
// controller
pos.controller('TestController', function($rootScope,$scope,$http) {
console.log($rootScope.authenticated);
});
It should print "true" or "false". I'm aware it assigns the value after the control executed but how to delay executing the controller until that value assigned ?