找出嵌套的ng-repeat是否显示任何内容

时间:2018-02-02 02:03:29

标签: javascript angularjs

我有一种情况,我有一个嵌套的ng-repeat,我需要弄清楚内部ng-repeat是否确实显示了任何内容,或者是否显示了任何内容。如果没有显示任何内容,则会显示一条消息,说明无法显示任何内容:

<div ng-repeat="area in $ctrl.specTplAreas">
    <div ng-repeat="item in $ctrl.items track by $index" 
       ng-if="item.specTemplateGroupId === area.id">displaying an item</div>
    <div ng-if="inner div above had no items to display">There are no items to display</div>
</div>

如何跟踪嵌套ng-repeat是否显示任何内容?

2 个答案:

答案 0 :(得分:1)

在控制器中过滤掉不匹配的项目

<div ng-repeat="item in $ctrl.items track by $index>
        Items are there
</div>
<div ng-hide="$ctrl.items.length"> Items are not there</div>

现在在.data()中,您将只拥有要显示的项目

$('#modallink').data('title');

答案 1 :(得分:0)

<div ng-repeat="area in $ctrl.specTplAreas"
    <div ng-repeat="item in $ctrl.items track by $index>
       <div ng-if="item.specTemplateGroupId === area.id"> Items are there</div>
       <div ng-if="item.specTemplateGroupId !== area.id"> Items are not there</div>
    </div>
</div>