Reputation: 137
I'm repeating through list of JSON object(nested) items like this :
<div ng-repeat='item in items'>
<ul>
<li ng-repeat='specific in item'>{{specific}}</li>
</ul>
</div>
I would like to present amount of 'specific' items in each item object at the top of the page(outside of ng-repeat scope). I cannot use items.length, becuase I would like to display amount of specific items(it has to be looped so), but I don't know how to bind the data from ng-repeat and use it outside it's scope..
Upvotes: 1
Views: 288
Reputation: 34
<span>Number of items : {{countItems(items.length)}}</span>
$scope.countItems = function(items) {
var count = 0;
for(var item in items) {
for(var specific in item) {
count++;
}
// Instead of the second for, you can just write :
// count = count + item.length;
}
return count;
};
It should do the trick :)
Upvotes: 1