加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 根据angular.js中的变量值更改ng-hide

发布时间:2020-12-17 09:28:15 所属栏目:安全 来源:网络整理
导读:我是一个newb的angular.js并且继承了代码.有一个使用ng-repeat显示的数据集(customerType).只有在customerType.type等于“new”时,我想显示3个表行.这3行在下面各自的标签中都有“ng-hide =”.如何在angular.js中执行此操作?我看到的指令似乎都适用于整个屏
我是一个newb的angular.js并且继承了代码.有一个使用ng-repeat显示的数据集(customerType).只有在customerType.type等于“new”时,我想显示3个表行.这3行在下面各自的标签中都有“ng-hide =”.如何在angular.js中执行此操作?我看到的指令似乎都适用于整个屏幕显示,所以我不知道如何更改只有部分显示的范围变量.这是html:
<div ng-repeat="customerType in customerTypes" class="span6">
  <table class="table table-bordered table-striped">
    <thead>
      <tr>
        <th colspan="3">
          <div class="span11 centered-text">
              {{customerType.title}}
          </div>
          <div class="span1">
              <a href="javascript:void(0);" ng-click="pullDetail(customerType.type,customerType.clients)" title="Details"><i class="icon-list-alt"></i></a>
          </div>
        </th>
      </tr>
      <tr>
        <th></th>
        <th>
          <div class="centered-text">
            Month Selected
          </div>
        </th>
        <th>
          <div class="centered-text">
            YTD
          </div>
        </th>
      </tr>                             
    </thead>
    <tbody>
      <tr>
        <td>Revenue</td>
        <td>{{customerType.month.revenue}}</td>
        <td>{{customerType.ytd.revenue}}</td>
      </tr>
      <tr>
        <td>Gross Profit</td>
        <td>{{customerType.month.gross}}</td>
        <td>{{customerType.ytd.gross}}</td>
      </tr>
      <tr>
        <td># of Customers</td>
        <td>{{customerType.month.customers}}</td>
        <td>{{customerType.ytd.customers}}</td>
      </tr>
      <tr>
        <td>Avg GP per Customer</td>
        <td>{{customerType.month.avg_gp}}</td>
        <td>{{customerType.ytd.avg_gp}}</td>
      </tr>
      <tr>
        <td># of Jobs</td>
        <td>{{customerType.month.jobs}}</td>
        <td>{{customerType.ytd.jobs}}</td>
      </tr>
      <tr ng-hide=>
        <td>First Time Client - Revenue</td>
        <td>{{customerType.month.ftc_revenue}}</td>
        <td>N/A</td>
      </tr>
      <tr ng-hide=>
        <td>First Time Client - Gross Profit</td>
        <td>{{customerType.month.ftc_gross}}</td>
        <td>N/A</td>
      </tr>
      <tr ng-hide=>
        <td>First Time Client - # of Customers</td>
        <td>{{customerType.month.ftc_customers}}</td>
        <td>-----</td>
      </tr>
      <tr ng-hide=>
        <td>First Time Client - # of Jobs</td>
        <td>{{customerType.month.ftc_jobs}}</td>
        <td>-----</td>
      </tr>
      <tr>
        <td>% on Contract</td>
        <td>{{customerType.month.contract}}</td>
        <td>{{customerType.ytd.contract}}</td>
      </tr>
    </tbody>
  </table>
</div>

这里是当前的指令:

var ReportController = function($scope,$http){
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";

$scope.filter = true;
$scope.report = false;
$scope.detail = false;

$scope.customerTypes = [];
$scope.detail_report = [];
$scope.companies = companies;
$scope.nsperiods = nsperiods;
$scope.users = users;

$scope.pullReport = function(sync){
    if(sync){
        var xsr = {request: 'report',company_no: $scope.company,nsperiod: $scope.nsperiod,users_no: $scope.user};
        $('form button').button('loading');
        $http({
            method: 'POST',headers: {'Content-Type': 'application/x-www-form-urlencoded'},transformRequest: function(obj) {
                var str = [];
                for(var p in obj)
                str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                return str.join("&");
            },data: xsr
        }).success(function(response){
            $scope.filter = false;
            $scope.report = true;
            $scope.detail = false;
            $('form button').button('reset');
            $scope.customerTypes = response;
        }).error(function(error){
            $('form button').button('reset');
            return;
        });
    }else{
        $scope.filter = false;
        $scope.report = true;
        $scope.detail = false;
    }
}

$scope.backToFilters = function(){
    $scope.filter = true;
    $scope.report = false;
    $scope.detail = false;
}

$scope.pullDetail = function(type,clients){
    var xsr = {
        request: 'detail',type: type,users_no: $scope.user
    };
    $http({
        method: 'POST',transformRequest: function(obj) {
            var str = [];
            for(var p in obj)
            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
            return str.join("&");
        },data: xsr
    }).success(function(response){
        $scope.filter = false;
        $scope.report = false;
        $scope.detail = true;
        $scope.detail_report = response;
    }).error(function(error){
        return;
    });                 
}
};

任何帮助将不胜感激.我正试图围绕这个问题,但是一些事情并没有完全相连.

只是根据该变量显示/隐藏?
我会做:
ng-show="customerType.type == 'new'"

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读