How to display length of filtered ng-repeat data

前端 未结 8 1341
花落未央
花落未央 2020-11-22 08:11

I have a data array which contains many objects (JSON format). The following can be assumed as the contents of this array:

var data = [
  {
    \"name\": \"         


        
8条回答
  •  不要未来只要你来
    2020-11-22 08:41

    Since AngularJS 1.3 you can use aliases:

    item in items | filter:x as results
    

    and somewhere:

    Total {{results.length}} result(s).
    

    From docs:

    You can also provide an optional alias expression which will then store the intermediate results of the repeater after the filters have been applied. Typically this is used to render a special message when a filter is active on the repeater, but the filtered result set is empty.

    For example: item in items | filter:x as results will store the fragment of the repeated items as results, but only after the items have been processed through the filter.

提交回复
热议问题