How to do paging in AngularJS?

后端 未结 21 1849
轮回少年
轮回少年 2020-11-22 07:17

I have a dataset of about 1000 items in-memory and am attempting to create a pager for this dataset, but I\'m not sure on how to do this.

I\'m using a custom filter

21条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 07:44

    Since Angular 1.4, the limitTo filter also accepts a second optional argument begin

    From the docs:

    {{ limitTo_expression | limitTo : limit : begin}}

    begin (optional) string|number
    Index at which to begin limitation. As a negative index, begin indicates an offset from the end of input. Defaults to 0.

    So you don't need to create a new directive, This argument can be used to set the offset of the pagination

    ng-repeat="item in vm.items| limitTo: vm.itemsPerPage: (vm.currentPage-1)*vm.itemsPerPage" 
    

提交回复
热议问题