AngularJS - controller data outside ng-view
I want to be able to access the isAuthenticated scope outside of the ng-view. I tried to add an ng controller to the body, the problem is that I can't access isAuthenticated because it is inside the permission block.
This is what I have:
.state('index', {
url: '/',
resolve: {
isAuthenticated: function($auth) {
return $auth.validateUser().then(function(res) {
return true;
}, function(error) {
return false;
});
}
},
controller: function($scope, isAuthenticated) {
$scope.isAuthenticated = isAuthenticated;
},
templateUrl: 'index.html'
})
I have two navbar states, one nav on the home page and another when the user is logged in.
<body>
<div ng-if="isAuthenticated">
<div ng-include="'user_navbar.html'"></div>
</div>
<div ng-if="!isAuthenticated">
<div ng-include="'home_navbar.html'"></div>
</div>
<div ui-view></div>
</body>
I dont want to place navbar in all my views, I dont want to duplicate code.
+3
source to share
No one has answered this question yet
Check out similar questions: