Angular UI Bootstrap 分页 - 在初始页面加载时在 ng-repeat 中显示前 12 条记录
Angular UI Bootstrap pagination - show first 12 records in ng-repat on inital page load
请参阅此 plunker 以了解我的问题的工作示例。
当我单击分页页码时分页工作正常,但最初并未加载第一页(第一组记录)的数据。当你点击一个数字时,它工作正常。
请注意:上面的plunker只是SO的一个demo,我的真实项目比较复杂,所以我不能只去掉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");
}
}
})();
更新了插件:http://plnkr.co/edit/2yHEukhKZcFplmJaFv0P
添加了一个函数updateView()
一旦数据首先加载到您的手表中,就会调用此函数
请参阅此 plunker 以了解我的问题的工作示例。
当我单击分页页码时分页工作正常,但最初并未加载第一页(第一组记录)的数据。当你点击一个数字时,它工作正常。
请注意:上面的plunker只是SO的一个demo,我的真实项目比较复杂,所以我不能只去掉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");
}
}
})();
更新了插件:http://plnkr.co/edit/2yHEukhKZcFplmJaFv0P
添加了一个函数updateView()
一旦数据首先加载到您的手表中,就会调用此函数