如何在选项卡内分页?

时间:2015-07-09 07:10:25

标签: html angularjs twitter-bootstrap filter pagination

我使用了UI Bootstrap分页,它自己完美运行。但是,当我添加标签(使用ul ling-show)时,分页不再有效。请注意,我还在我想要分页的内容上使用filter(在Angular中)。

这是我的代码 - 也在JSFiddle上:http://jsfiddle.net/efaLj8a0/

<ul ng-init="tabQ = 1">
  <li ng-class="{active:tabQ===1}">
    <a href ng-click="tabQ = 1">Newest</a>
  </li>
  <li ng-class="{active:tabQ===2}">
    <a href ng-click="tabQ = 2">Hottest</a>
  </li>
</ul>
<div ng-show="tabQ === 1">
    <ul class="striped-list">
        <li ng-repeat="question in questions | startFrom:begin | limitTo:itemsPerPage | filter:orderProp">
        </li>
    </ul>
</div>
<pagination total-items="totalItems" page="currentPage" max-size="maxSize" class="pagination-sm" boundary-links="true" rotate="false" direction-links="false" rotate="false" items-per-page="itemsPerPage" on-page-change="pageChanged()"></pagination>

controller.js

$scope.itemsPerPage = 15;    
$scope.$watch('questions.length', function(length) {
  if(length) {
    $scope.totalItems = $scope.questions.length;
  }
});
$scope.currentPage = 1;
$scope.maxSize = 5;
$scope.$watch('currentPage', function(pageChanged) {
  $scope.begin = ($scope.currentPage-1)*$scope.itemsPerPage;
});

0 个答案:

没有答案