1
我已經拿出this plunker來顯示我的問題。從角度和分頁獲取下一組和前一組記錄
我在尋找的行爲是,當用戶點擊右箭頭時,它會轉到下一頁,左箭頭轉到上一頁。如果用戶在第10頁上,那麼當點擊右箭頭時,突出顯示分頁鏈接上顯示的頁數2-11和11。
如果他們再次點擊右箭頭,它會更改3-12和12中分頁鏈接上顯示的頁面數。這將繼續進行,直到第20頁達到,然後不會讓他們進一步。如果第1頁上的用戶點擊左箭頭不起作用,還應該通過遞減來繼續工作。希望這是明確的。
HTML:
<ul class="pagination pagination-lg">
<li class="page-item">
<a href="#" ng-click="search($index-1)"> <span aria-hidden="true">«</span> <span class="sr-only">Previous</span> </a>
</li>
<li ng-class="currentPage === $index+1 ? 'active' : ''" ng-repeat="i in getNumber(numberOfPages) track by $index"><a class="page-link" href="#" ng-click="search($index+1)">{{$index+1}}</a></li>
<li class="page-item">
<a href="#" ng-click="search($index+1)"> <span aria-hidden="true">»</span> <span class="sr-only">Next</span> </a>
</li>
</ul>
角/ JS:
$scope.search = function(index){
$scope.currentPage = index;
$http.get('https://jsonplaceholder.typicode.com/todos').then(function (response) {
var temp = response.data;
$scope.data = temp.splice(pageSize * (index-1), 10);
})
}
完全代碼見this plunker。任何幫助讚賞。