【发布时间】:2017-02-12 15:36:09
【问题描述】:
请参阅此plunker,了解我的问题的工作示例。
当我单击分页页码但最初没有加载第一页(第一组记录)的数据时,分页正在工作。当你点击一个数字时,它就可以正常工作了。
请注意:上面的 plunker 只是 SO 的一个演示,我的实际项目更复杂,所以我不能摆脱 dataService 等。
var app = angular.module('plunker', ['ui.bootstrap.tpls', 'ui.bootstrap.pagination']);
app.controller('MainCtrl', function($scope, dataService) {
$scope.data = [];
dataService.getAll()
.then(function (response) {
// Success
$scope.data = response.data;
$scope.totalItems = $scope.data.length;
}, function (data, status, header, config) {
// Failure
});
$scope.itemsPerPage = 12;
$scope.currentPage = 1;
$scope.pageCount = function () {
return Math.ceil($scope.data/ $scope.itemsPerPage);
};
$scope.$watch('currentPage + itemsPerPage', function () {
var begin = (($scope.currentPage - 1) * $scope.itemsPerPage),
end = begin + $scope.itemsPerPage;
$scope.filtered = $scope.data.slice(begin, end);
});
});
//数据服务
(function() {
"use strict";
angular.module("plunker").factory("dataService", dataService);
function dataService($http) {
return {
getAll: getAll
}
function getAll() {
return $http.get("http://api.scb.se/OV0104/v1/doris/en/ssd");
}
}
})();
【问题讨论】:
标签: angularjs pagination angularjs-ng-repeat angular-ui-bootstrap