krammer
krammer

Reputation: 2658

Generate href list dynamically in AngularJS

I am implementing server side pagination in AngularJS following the code at laravel-tricks

I pass pageNumber to the API and it returns the total number of results and other data on that page in the results. The data is then displayed in the table.

How can I generate a list of hrefs for pages dynamically when the results are received ?

Note 1: I have tried ngTable, but it doesn't update the table when the data is changed though it does update the model. Hence resorted to manual pagination since I need a basic pagination only

Note 2: I am not using Bootstrap there for pagination provided by AngularUI is not of any use.

Upvotes: 0

Views: 412

Answers (1)

Bradley Trager
Bradley Trager

Reputation: 3590

You can do something like this:

//Generate pagination buttons, each with the ng-click directive
<button ng-repeat="pageNumber in [1, 2, 3, 4, 5]" ng-click="goToPage(pageNumber)">
  <span ng-bind="pageNumber"></span>
</button>

Then have a goToPage function in your controller like this:

 $scope.goToPage = function(pageNumber) {    
     $scope.main.page = pageNumber;
     $scope.loadPage();    
 };

NOTE: I just used [1, 2, 3, 4, 5] as an example, but you may want to generate that array in your controller.

Upvotes: 1

Related Questions