I have come up with this plunker to show my issue.
The behaviour that I am looking for is that when the user clicks on the right arrow it goes to next page and the left arrow to the previous page. If user is on page 10 then when clicks right arrow changes the number of pages shown on pagination links from 2-11 and 11 is highlighted.
If they click on right arrow again it changes the number of pages shown on pagination links from 3-12 and 12 is highlighted. This would carry on until page 20 reached then would not allow them any further. Should also work going in previous direction also by decrementing, if user on page 1 clicking on the left arrow has no effect. Hope this is clear.
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>
Angular/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);
})
}
See this plunker for full code. Any help appreciated.