tommyd456 tommyd456 -5 years ago 156
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?

Answer Source

Use this:

<span>{{ (places | filter : { category: 'city' }).length }}</span>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download