我希望在ng-view之外访问范围isAuthenticated。我试图将ng-controller添加到正文中,问题是我无法访问isAuthenticated,因为它在解析块中。
这就是我所拥有的:
.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'
})
我有两个导航栏状态,主页上有一个导航栏,用户登录时有另一个导航栏。
<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>
我不想将导航栏放在我的所有视图中,我不想复制代码。