Reputation: 10683
I have an array of objects called places
where each object looks something like this:
{
"name" : "London",
"category" : "city"
}
I just use <span>{{places.length}}</span>
for the total array length but now I would like to count the number of objects that have a category of city
ideally using a filter directly within the view.
Something like:
{{places.length | filter: ...}}
but not sure how to write the filter?
Upvotes: 2
Views: 4397
Reputation: 4395
Use this:
<span>{{ (places | filter : { category: 'city' } : true).length }}</span>
Upvotes: 6