How to use ng-repeat with filter and $index?

前端 未结 6 1314
南笙
南笙 2020-12-08 07:33

I want to use ng-repeat in Angular, while I only want to output some elements of the array. An Example:

ng-repeat=\"item in items | filter:($index%3 == 0)\"
         


        
6条回答
  •  再見小時候
    2020-12-08 08:02

    In your code, filter apply on 'items' array, not on each array item, that's why it does not work as you expect.

    Instead, you can use ng-show (or ng-if):

    • {{item}}

    See: http://jsfiddle.net/H7d26

    EDIT: Use ng-if directive if you do not want to add invisible dom elements:

    • {{item}}

提交回复
热议问题