Pagination not working AngularJS 1.4 with ui-bootstrap -


here's have (i've tried numerous things other answers , tutorials no avail):

simpleimagereview.js:

var app = angular.module("simpleimagereview", ['ui.bootstrap']); 

imgviewerctrl.js:

app.controller("imgviewerctrl", function($scope, $http) {     $scope.imglist = [];     $http.get("http://127.0.0.1:5000/api/file_metadata").success(         function(data, status, headers, config) {             $scope.data = data;             $scope.totalimgs = $scope.data.num_results;             $scope.totalpages = $scope.data.total_pages;             $scope.currentpage = $scope.data.page;             $scope.imglist = $scope.data.objects;             $scope.imgsperpage = 10;         }); }); 

index.html (stripped down):

... header, imports, etc. - no issues  <body ng-app="simpleimagereview"> <div ng-controller="imgviewerctrl">     <ul>         <li>             <li ng-repeat="img in imglist">                 <img src="{{img.local_path}}" border="0" width="153" height="204">         </li>     </ul>      <pagination          total-items="totalimgs"          items-per-page="imgsperpage"          ng-model="currentpage"          max-size="totalpages"          class="pagination-sm"          boundary-links="true">     </pagination> </div> </body>  ... footer, more imports - no issues 

the images display fine api working intended. clicking on next page nothing. imagine somehow need update view not sure how go this.

what doing wrong?

you need manually create new array containing subset of objects displayed on current page. point ng-model array not whole data array. on page load, assuming want begin on first page:

$scope.paginatedlist = $scope.imglist.slice(0, $scope.imgsperpage); 

you need use ng-change directive on pagination directive can use update paginatedlist when $scope.currentpage changes.

in html...

<pagination              ng-change="pagechanged()"             total-items="totalimgs"              items-per-page="imgsperpage"              ng-model="currentpage"              max-size="totalpages"              class="pagination-sm"              boundary-links="true">     </pagination> 

in controller...

$scope.paginatedlist = $scope.imglist.slice(0, $scope.imgsperpage);  function pagechanged(){        var begin = (($scope.currentpage - 1) * $scope.imgsperpage),           end   = begin + $scope.imgsperpage;        $scope.paginatedlist = $scope.imglist.slice(begin, end);  } 

here working plunker


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -