隐藏前面的一些元素,因为用户有权限

时间:2015-12-19 17:30:22

标签: jquery html angularjs

我的授权问题。在客户端,我使用了这段代码

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.');
       }

在成功登录之前我想在前面隐藏一些元素。请告诉我如何做到这一点。

1 个答案:

答案 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.');
}