I have a simple angular app with a Main Controller and a child controller. 
Maincontroller loads the login page and on successful login, a welcome page 
is loaded in using the child controller. The app is simple one and is 
working. My issue is to set the logged in user name after successful login.


My Main controller


.controller('mainController', function($rootScope, $location, Auth) {

var vm = this;  
vm.loggedinUser = Auth.getActiveUser();  
console.log(">>>>>>   ", vm.loggedinUser);  

//check to see user is logged in for every request made  
$rootScope.$on('$routeChangeStart', function() {  
    vm.loggedIn = Auth.isLoggedIn();  

});  

My html page is simple:


<body ng-app="bookapp" ng-controller="mainController as main">
.. <li class="navbar-text">Hello {{ main.loggedinUser }}! >


Issue is that loggedinUser value is not displayed.


1) For it to work i have to initialize the loggedinUser value within the 
routechange listener.(moving the line to within listener works). Why is it 
so?

2) Also note that the console.log statement prints the real value after log 
in and when the welcome page is displayed. But variable value is set in 
main Controller during the application load itself(login page) and can only 
be changed through route change listener. It is not re-initialized during 
welcome page load.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to