tommyd456 tommyd456 - 1 year ago 57
AngularJS Question

Using filter to count array length with condition

I have an array of objects called

where each object looks something like this:

"name" : "London",
"category" : "city"

I just use
for the total array length but now I would like to count the number of objects that have a category of
ideally using a filter directly within the view.

Something like:

{{places.length | filter: ...}}

but not sure how to write the filter?


Use this:

<span>{{ (places | filter : { category: 'city' }).length }}</span>