3
How to make a pagination on demand with Angularjs? I have 2 particularities:
1 - No jQuery, only Angular or pure Javascript can be used.
2 - I have 2 methods the prevPage
and nextPage
.
Below example 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 is currently working, but the page only loads 10 pages of pagination, but if the number increases it will surely break.
Here you go an example of paging as a matter of how I want to do.
What you want is the reticence part when there are too many pages?
– bfavaretto
Exactly @bfavaretto!
– Edmo
To mark bfavaretto in your comment use the @ before the name thus @bfavaretto
– Silvio Andorinha