2016-10-20 77 views
0

我創建了一些動態的表,它們都有一些行也是使用Angular動態創建的。隱藏容器,如果所有的孩子都隱藏在角

我的目標是讓每個表都隱藏,如果該表的tbody中沒有可見的行。

<table ng-repeat="package in listOfPackages" ng-if="this.getElementsByTagName('tbody')[0].childNodes.length > 0 "> 
    <tbody> 
    <tr ng-repeat="thing in package.things" ng-if="thing.status === 'interesting'"> 
     <td>{{thing.someInfo}}</td> 
     <td>{{thing.someOtherInfo}}</td> 
    </tr> 
    </tbody> 
</table> 

ng-if="this.getElementsByTagName('tbody')[0].childNodes.length > 0"似乎是我的問題 - 我不知道正確的方式找到一個元素的自己的孩子,並檢查它多少有明顯的。

是否有任何可能的方式來做到這一點在角?

+0

您可以使用返回真/假取決於條件的函數 – Akis

回答

0

在你的控制器類似

$scope.showPackageTable = function (package) { 
    var toShow = false; 
    for (var thing in package.things) { 
     if (thing.status === 'interesting') { toShow = true; } 
    } 
    return toShow; 
} 

創建一個功能,那麼你可以使用在你的HTML ng-if="showPackageTable(package)"