I'm a newbie to angularjs.
My problem is that I have a User Controller for handling Login and Logout. I have also another controller to load a header menu for my site.
If the user logs in to the site my isAuthenticated variable is set to true. If the variable is set to true the header should be change but, so I think the controller must be reloaded to change the header view.
Here the code of my HeaderController:
myapp.controller('HeaderController', ['$scope', '$location', '$window', 'AuthenticationService',
function HeaderController($scope, $location, $window, AuthenticationService) {
$scope.isAuthenticated = AuthenticationService.isAuthenticated;
if (AuthenticationService.isAuthenticated) {
$scope.user.vorname = $window.sessionStorage.user.vorname;
}
}
]);
Here's the code of my HeaderDirective:
myapp.directive('appHeader', function() {
return {
restrict: 'E',
link: function(scope, element, attrs) {
if (attrs.isauthenticated == 'false') {
scope.headerUrl = 'views/header/index.html';
} else {
scope.headerUrl = 'views/header/isAuthenticated.html';
}
},
template: '<div ng-include=headerUrl></div>'
}
});
My index.html:
<div ng-controller=HeaderController>
<app-header isauthenticated={{isAuthenticated}}></app-header>
</div>
How can I reload the controller if the user logs in to the page?
PS: Please excuse my poor pronunciation.