I have a header view as
<div ng-controller="navCtrl">
<ul class="nav navbar-nav" ng-show="isAuthenticated">
<li> <a ui-sref="logout"> Logout </a> </li>
</ul>
</div>
The navigation controller
(function(){
var navigationController = function($scope, authToken){
$scope.isAuthenticated = authToken.isAuthenticated(); //return bool
};
navigationController.$inject = ['$scope','authToken'];
angular.module('simpleApp')
.controller('navCtrl', navigationController);
}());
I have another logout controller
(function(){
var logoutController = function($scope ,authToken, $state){
$scope.isAuthenticated = false;
$state.go('main');
};
logoutController.$inject = ['$scope', 'authToken', '$state'];
angular.module('simpleApp')
.controller('logoutCtrl', logoutController);
}());
When I click on the Logout link i set $scope.isAuthenticated = false; , expecting the navigation menu to hide but it dosent.
Something seems to be done in the wrong way :(
$scope. how would you expect changing a property on one of them to affect the other two?$scopeis created any time that an element has anng-controllerattached. unless they are nested (and they are not, in your case), each element group (i.e. from<div>to</div>) are separate. in other words, you cannot change a$scopeproperty in one controller and see the effect of that change in another. You need to use Services or events to share data between controllers.