我的授权问题。在客户端,我使用了这段代码
if (_.isNull(window.localStorage.getItem("username"))) {
MEDService.testUser($scope.user)
.success(function(data, status, headers, config) {
console.log(data);
if (data == "OK") {
window.localStorage.setItem("username", $scope.user.username);
window.localStorage.setItem("password", $scope.user.password);
$rootScope.user = $scope.user;
$location.path('/');
} else {
alert('Incorrect! Please check your username and password.');
}
在成功登录之前我想在前面隐藏一些元素。请告诉我如何做到这一点。
答案 0 :(得分:0)
您需要在控制器范围内设置标志,&然后在ng-show
/ ng-if
<强> HTML 强>
<div ng-if="isLoaded">
Content
</div>
<强>代码强>
if (_.isNull(window.localStorage.getItem("username"))) {
//before loading set it to false
$scope.isLoaded = false;
MEDService.testUser($scope.user)
.success(function(data, status, headers, config) {
console.log(data);
if (data == "OK") {
window.localStorage.setItem("username", $scope.user.username);
window.localStorage.setItem("password", $scope.user.password);
$rootScope.user = $scope.user;
$scope.isLoaded = true;
//after loaded set it to true
$location.path('/');
} else {
alert('Incorrect! Please check your username and password.');
}