当用户登录我的系统注销按钮时出现并且记录时我需要 out按钮消失实现我首先按下按钮点击下面的按钮 代码:
$scope.test = function () {
if ($rootScope.authenticated) {
$rootScope.authenticated = false;
} else {
$rootScope.authenticated = true;
}
}

<li class="dropdown" id="profile-messages" ng-class="authenticated ? 'show' : 'hide' " @*ng-show="authenticated"*@>
<a title="" href="#" data-toggle="dropdown" data-target="#profile-messages" class="dropdown-toggle">
<i class="icon icon-user"></i>
<span class="text" ng-model="username">{{username}}</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="#"><i class="icon-user"></i> {{user.authenticated}}</a></li>
<li class="divider"></li>
<li><a href="#"><i class="icon-check"></i> My Tasks</a></li>
<li class="divider"></li>
<li><a href="#" ng-show="user.authenticated" ng-click="logout()"><i class="icon-key"></i> خروچ</a></li>
</ul>
</li>
<li class=""><a title="" href="#" ng-click="logout()" ng-show="authenticated"><i class="icon icon-share-alt"></i> <span class="text">Logout</span></a></li>
<input type="button" id="test" value="test" ng-click="test()" />
&#13;
当点击按钮时,每件事都运行正常,但是当我在登录功能中完成相同的方式时,我使用以下代码无效
$scope.login = function () {
var hasError = false;
if (!hasError) {
if (!$rootScope.authenticated) {
var result = LoginFactory.adminLogin($scope.loginForm);
result.then(function (result) {
if (!result.ok) {
toastr.warning(result.Message, 'اخطار', { timeOut: 7000 });
} else {
$location.path(result.url);
$rootScope.authenticated = result.authenticated;
$rootScope.username = result.user;
}
})
} else {
toastr.error("you are already logged In!", '', { timeOut: 0 });
}
}
&#13;
我的服务是:
adminLogin: function (model) {
var deferredObject = $q.defer();
$http.post('/Core/User/LoginApp', { model: model }).success(function (data) {
if (!data.Ok) {
deferredObject.resolve({ ok: false, Message: data.Message });
} else {
deferredObject.resolve({ ok: true, url: data.Url, user: data.User, authenticated: data.authenticated });
}
}).error(function () {
deferredObject.resolve({ success: false, Message: data.Message });
});
return deferredObject.promise;
}
&#13;
我该如何解决这个问题
答案 0 :(得分:0)
使用双重否定使其成为boolean
。
$rootScope.authenticated = !! result.authenticated;