2016-04-21 25 views
0

我有这个分页代码的问题。我有1个按钮,而不是3个。你能帮忙吗?角1按钮而不是3

paginator.js

$scope.generateButtons = function() { 
     var buttons = [], 
      pageCount = getPageCount(), 
      buttonCount; 


     console.log("page " + pageCount); 

     buttonCount = pageCount > 2 ? 3 : pageCount; 

     for (var i = 0; i < buttonCount; i++) { 
      var index = +$scope.offset + i -1; 
      if (index > 0) { 
       buttons.push(index); 
      } 
     }; 

     return buttons; 
    }; 

View in plunker

回答

1

我的建议是使用角UI引导分页,而不是从头开始写https://angular-ui.github.io/bootstrap/#/pagination

angular.module('ui.bootstrap.demo').controller('PaginationDemoCtrl', function ($scope, $log) { 
    $scope.totalItems = 64; 
    $scope.currentPage = 4; 

    $scope.setPage = function (pageNo) { 
    $scope.currentPage = pageNo; 
    }; 

    $scope.pageChanged = function() { 
    $log.log('Page changed to: ' + $scope.currentPage); 
    }; 

    $scope.maxSize = 5; 
    $scope.bigTotalItems = 175; 
    $scope.bigCurrentPage = 1; 
}); 
+0

我不会使用Angular UI bootstrap分页,因为我学习基本的:) –

0

这真的不是角相关问题。其全部关于$scope.generateButtons = function() {...}的逻辑请根据需要更改您的逻辑。这里是你的代码(编辑)显示3个按钮。

$scope.generateButtons = function() { 
     var buttons = [], 
      pageCount = getPageCount(), 
      buttonCount; 

     buttonCount = pageCount > 2 ? 3 : pageCount; 

     for (var i = 0; i < buttonCount; i++) { 
      var index = parseInt($scope.offset) + i+1; 

      if (index >= 0) { // this `if` is not really needed 
       buttons.push(index); 
      } 
     }; 

     return buttons; 
    }; 

享受!