【发布时间】:2015-11-18 05:33:45
【问题描述】:
我有一个登录页面,显示在我的 index.html 页面中。 index.html 页面可以控制一个导航栏,在用户成功登录之前我不想显示该导航栏。但是,在他们登录后,导航栏 ng-show 属性不会更新,因为我有它代码。这是说明的代码:
<nav class="navbar navbar-inverse" ng-controller="loginController" ng-show={{valid}}>
<div class="collapse navbar-collapse navbar-collapse-links">
<ul class="nav navbar-nav">
<li><a ui-sref="addUser" class="addUser" >Add User</a></li>
<li><a ui-sref="listUser" class="mdUser">Modify User</a></li>
<li><a ui-sref="login" class="mdUser">Logout</a></li>
</ul>
</div>
</nav>
我的控制器内部是这样的:
$scope.valid = false;
function login() {
AuthenticationService.Login(vm.user.username, vm.user.password, function (response) {
if (response.success) {
AuthenticationService.SetCredentials(response.token.UserName, response.token.TokenId);
$scope.valid = true;
$location.path('/');
} else {
//FlashService.Error(response.message);
vm.error = response.message;
vm.dataLoading = false;
}
....
)};
}
这些是对代码的粗略复制和粘贴,仅包含我认为当前问题所必需的内容。
我可以手动将声明更改为 true 或 false,并让导航栏正确运行。否则,在有效登录尝试后导航栏不会显示,并且当我登录后在控制台中检查 html 时,ng-show 方法仍然显示为 false。
问题:为什么在我的成功函数中重新分配有效绑定后无法正确更改?
【问题讨论】:
-
你的 authenticationService 是什么?旁注,ng-show 不需要 {{}}。
ng-show="valid"很好 -
它是一项自定义服务,我必须通过我们的后端进行身份验证。已完成测试及其工作方式应该如何......应该不是问题
标签: javascript html angularjs data-binding ng-show