如何使用 Angular 的 UI Bootstrap 分页指令进行服务器端分页

2023-12-30

您好,我们想要使用 Angular 的 UI Bootstrap 分页指令进行服务器端分页。我们知道如何创建 RESTful 端点来从我们的服务器提供页面,但没有看到任何有关如何将该端点连接到 Angular 的 UI Bootstrap 分页指令的文档。


请看下面的小演示

angular.module('app', ['ui.bootstrap']);
angular.module('app').controller('PaginationDemoCtrl', function($scope, $http) {

  $scope.currentPage = 1;
 $scope.limit= 10;


  $scope.tracks = [];
  getData();


  function getData() {
    $http.get("https://api.spotify.com/v1/search?query=iron+&offset="+($scope.currentPage-1)*$scope.limit+"&limit=20&type=artist")
      .then(function(response) {
        $scope.totalItems = response.data.artists.total
        angular.copy(response.data.artists.items, $scope.tracks)


      });
  }

//get another portions of data on page changed
  $scope.pageChanged = function() {
    getData();
  };


});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>


<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.12.0.js"></script>

<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">

<body ng-app="app">

  <div ng-controller="PaginationDemoCtrl">
    <h4>Sample Server Pagination</h4>

    <pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()" items-per-page="100"></pagination>
    <ul>
      <li ng-repeat="track in tracks" style="list-style:none">
<img ng-src="{{track.images[2].url}}" alt="" width="160"/>
{{track.name}}</li>
    </ul>

  </div>
</body>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Angular 的 UI Bootstrap 分页指令进行服务器端分页 的相关文章

随机推荐