2017-01-10 16 views
2

我創建在其中,我有一個表秀angularjs表,如果表中有一行

<div class="table-responsive scroll" ng-hide="hidetable"> 
    <table id="table" class="table table-bordered table-condensed"> 
     <thead> 
       <tr class="bg-primary"> 
        <th><a href="#" class="erp-tb-a" ng-click="order('date')">Date</a></th> 
        <th><a href="#" class="erp-tb-a" ng-click="order('day')">Day</a></th> 
        <th><a href="#" class="erp-tb-a" ng-click="order('brandname')">BrandName</a></th> 
        <th><a href="#" class="erp-tb-a" ng-click="order('zone')">Zone</a></th> 
        <th><a href="#" class="erp-tb-a" ng-click="order('location')">Location</a></th> 
        <th><a href="#" class="erp-tb-a" ng-click="order('area')">Area</a></th> 
        <th><a href="#" class="erp-tb-a" ng-click="order('trainer')">TrainerName</a></th> 
        <th><a href="#" class="erp-tb-a" ng-click="order('program')">Program</a></th> 
        <th><a href="#" class="erp-tb-a" ng-click="order('trainingno')">Training Id</a></th> 
        <th><a href="#" class="erp-tb-a" ng-click="order('amount')">Amount</a></th> 
        <th><a href="#" class="erp-tb-a">Remark</a></th> 
        <th><a href="#" class="erp-tb-a" ng-click="order('sonvinid')">SonvinId</a></th> 
        <th><a href="#" class="erp-tb-a" ></a>Add</th> 
       </tr> 
       <tr class="bg-primary"> 
        <td><input type="text" class="erp-input" ng-model="search.date" /></td> 
        <td><input type="text" class="erp-input" ng-model="search.day" /></td> 
        <td><input type="text" class="erp-input" ng-model="search.brandname" /></td> 
        <td><input type="text" class="erp-input" ng-model="search.zone" /></td> 
        <td><input type="text" class="erp-input" ng-model="search.location" /></td> 
        <td><input type="text" class="erp-input" ng-model="search.area" /></td> 
        <td><input type="text" class="erp-input" ng-model="search.trainer" /></td> 
        <td><input type="text" class="erp-input" ng-model="search.program" /></td> 
        <td><input type="text" class="erp-input" ng-model="search.trainingno" /></td> 
        <td><input type="text" class="erp-input" ng-model="search.amount" /></td> 
        <td><input type="text" class="erp-input" /></td> 
        <td><input type="text" class="erp-input" ng-model="search.sonvinid" /></td> 
        <td></td> 
       </tr> 
      </thead> 
      <tbody> 
       <tr ng-repeat="p in getallcompany | orderBy:predicate:reverse | filter:search"> 
        <td>{{p.date}}</td> 
        <td>{{p.day}}</td> 
        <td>{{p.brandname}}</td> 
        <td>{{p.zone}}</td> 
        <td>{{p.location}}</td> 
        <td>{{p.area}}</td> 
        <td>{{p.trainer}}</td> 
        <td>{{p.program}}</td> 
        <td>{{p.trainingno}}</td> 
        <td>{{p.amount}}</td> 
        <td><input type="text" class="erp-input" style="width:90%; border:1px solid black;" ng-model="mdremarks" /></td> 
        <td>{{p.sonvinid}}</td> 
        <td><md-checkbox tabindex="0" area-label="none" role="checkbox" ng-click="clickcheckbox()"></md-checkbox></td> 
       </tr> 
      </tbody> 
    </table> 
    <div style="margin-bottom:20px"> 
     <a href="#" style="cursor:pointer;" class="btn btn-primary active">Generate Bill</a> 
     <a href="#" style="cursor:pointer;" class="btn btn-warning active">Back</a> 
    </div> 


</div> 

這是我的表,我的第一個div我用

ng-hide="hidetable" 
mvc5 angularjs一個基於Web的應用程序

現在我想要的是如果表是空的(即)如果從sql返回的值沒有行,表應該隱藏,如果返回的值有行,表應該顯示

var app = angular.module('myapp', ['ngMaterial']); 
app.controller('mycontroller', function ($scope, $http) { 
      $scope.hidetable = true; 

,這是我的控制器和表將在頁面加載

$http.get('/freezeservice.asmx/gettabledetails', { 
       params: { 
        log: log, 
        pm: pm, 
        comname: $scope.mdcompany, 
        mm: $scope.datemm, 
        yy: $scope.dateyy 
       } 
      }) 
       .then(function (response) { 
        { 
         $scope.getallcompany = response.data.info; 

        } 
       }); 

被隱藏這就是我如何獲取我的數據

需要你的幫助

回答

1

對我來說最好的方式做到這一點,

做出改變你的控制器

  $http.get('/freezeservice.asmx/gettabledetails', { 
       params: { 
        log: log, 
        pm: pm, 
        comname: $scope.mdcompany, 
        mm: $scope.datemm, 
        yy: $scope.dateyy 
       } 
      }) 
       .then(function (response) { 
        { 
         $scope.getallcompany = response.data.info; 
         console.log(response.data.info.length); 
         if(response.data.info.length===0) 
         { 
          alert('No Data Related To This'); 
          $scope.hidetable = true; 
         } 
         else if(response.data.info.length > 0) 
         { 
          $scope.hidetable = false; 
         } 
        } 
       }); 

這裏如果你的數據的長度爲0,則$scope.hidetable = true;這將運行其他$scope.hidetable = false;這將運行

0

只需添加ng-if條件。您可以使用ng-showng-hide

<table ng-if="getallcompany.length"> 
+0

它不應該是一個像ng-if =「getallcompany.length> 0」的布爾表達式嗎? –

+0

這也很好 –