AngularJS: Count Filtered Items

前端 未结 4 1708
醉话见心
醉话见心 2020-12-31 03:31

I am showing subsets of a list if a checkbox is checked. I would like to replace the X next to the checkbox with the count of the list matching the selection criteria. I hav

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 04:05

    Assuming your list of people is in data variable and you filter people using query model, the following code will work for you:

    • Number of visible people: {{(data|filter:query).length}}
    • Total number of people: {{data.length}}

    summary

    {{data.length}} - prints total number of people

    {{(data|filter:query).length}} - prints filtered number of people

提交回复
热议问题