BeniaminoBaggins
BeniaminoBaggins

Reputation: 12433

Find out if nested ng-repeat displayed anything

I have a situation where I have a nested ng-repeat and I need to figure out if the inner ng-repeat actually did display anything or if nothing was shown. And if nothing was shown, display a message saying there was nothing to display:

<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>

How can I track if the nested ng-repeat displayed anything?

Upvotes: 0

Views: 107

Answers (2)

Vamsi
Vamsi

Reputation: 9780

In Controller filter out items that doesn't match

$scope.items = $scope.items.filter(function (item) {
    return $scope.specTplAreas.find(function (area) {
        return area.id == item.specTemplateGroupId;
    })
});

now in items you will have only the items you want to display

<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>

Upvotes: 1

Sajeetharan
Sajeetharan

Reputation: 222582

<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>

Upvotes: 0

Related Questions