How to do paging in AngularJS?

后端 未结 21 2237
轮回少年
轮回少年 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:50

    For anyone who find it difficult like me to create a paginator for a table I post this. So, in your view :

                  
            
         
    //And don't forget in your table:

    In your angularJs:

      var module = angular.module('myapp',['ui.bootstrap','dialogs']);
      module.controller('myController',function($scope,$http){
       $scope.total = $scope.mylist.length;     
       $scope.currentPage = 1;
       $scope.itemPerPage = 2;
       $scope.start = 0;
    
       $scope.setItems = function(n){
             $scope.itemPerPage = n;
       };
       // In case you can replace ($scope.currentPage - 1) * $scope.itemPerPage in  by "start"
       $scope.pageChanged = function() {
            $scope.start = ($scope.currentPage - 1) * $scope.itemPerPage;
                };  
    });
       //and our filter
         module.filter('offset', function() {
                  return function(input, start) {
                    start = parseInt(start, 10);
                    return input.slice(start);
                  };
                });     
    

提交回复
热议问题