How to make a paging on demand with AngularJS? I have 2 particularities:
1 - You can not use jQuery, just Angular or pure JavaScript.
2 - I have 2 methods the prevPage
and nextPage
.
Here are some examples of the methods:
$scope.prevPage = function(page){
if($scope.currentPage-1 > 0){
$scope.changePage(page);
}
}
$scope.nextPage = function(page){
if($scope.currentPage+1 <= $scope.numberOfPages){
$scope.changePage(page);
}
}
Here, to be more visible, you have HTML:
<ul class="pagination">
<li class="glyphicon glyphicon-chevron-left" ng-click="prevPage(currentPage-1)" ng-class="{disabled: currentPage == 1}"></li>
<li ng-repeat="i in numberOfPagesArr track by $index" ng-class="{active: $index+1 == currentPage}" ng-click="changePage($index+1)">{{$index+1}}</li>
<li class="glyphicon glyphicon-chevron-right" ng-click="nextPage(currentPage+1)" ng-class="{disabled: currentPage == numberOfPages}"></li>
</ul>
It's currently up and running, but the page loads only 10 paging pages, but if you increase the number it will surely break.
Here's an example of paging in question of how I want to do it.