【发布时间】:2014-10-02 22:27:24
【问题描述】:
我是 angularjs 的新手。
我的问题是我有一个用于处理登录和注销的用户控制器。我还有另一个控制器来为我的站点加载标题菜单。
如果用户登录到站点,我的 isAuthenticated 变量设置为 true。如果变量设置为true,则标题应该更改但是,所以我认为必须重新加载控制器才能更改标题视图。
这里是我的 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;
}
}
]);
这是我的 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>'
}
});
我的 index.html:
<div ng-controller="HeaderController">
<app-header isauthenticated="{{isAuthenticated}}"></app-header>
</div>
如果用户登录页面,如何重新加载控制器?
PS:请原谅我发音不好。
【问题讨论】:
标签: javascript angularjs controller