为了账号安全,请及时绑定邮箱和手机立即绑定

如何做分页AngularJS

如何做分页AngularJS

qq_遁去的一_1 2019-03-28 18:18:19
如何做分页AngularJS
查看完整描述

2 回答

?
隔江千里

TA贡献1906条经验 获得超10个赞

app.controller('BusinessCtrl', ['$scope', '$rootScope', 'BusinessService', function ($scope, $rootScope, BusinessService) {
$rootScope.title = '流水列表';

$scope.currentPage = 1;
$scope.totalPage = 1;
$scope.pageSize = 40;
$scope.pages = [];
$scope.endPage = 1;
//获取总流水
BusinessService.total().success(function (data) {
$scope.total = data;
});

$scope.load = function () {
BusinessService.list($scope.currentPage, $scope.pageSize).success(function (data) {
$scope.items = data.list;
//获取总页数
$scope.totalPage = Math.ceil(data.count / $scope.pageSize);
$scope.endPage = $scope.totalPage;
//生成数字链接
if ($scope.currentPage > 1 && $scope.currentPage < $scope.totalPage) {
$scope.pages = [
$scope.currentPage - 1,
$scope.currentPage,
$scope.currentPage + 1
];
} else if ($scope.currentPage == 1 && $scope.totalPage > 1) {
$scope.pages = [
$scope.currentPage,
$scope.currentPage + 1
];
} else if ($scope.currentPage == $scope.totalPage && $scope.totalPage > 1) {
$scope.pages = [
$scope.currentPage - 1,
$scope.currentPage
];
}
});
};

$scope.next = function () {
if ($scope.currentPage < $scope.totalPage) {
$scope.currentPage++;
$scope.load();
}
};

$scope.prev = function () {
if ($scope.currentPage > 1) {
$scope.currentPage--;
$scope.load();
}
};

$scope.loadPage = function (page) {
$scope.currentPage = page;
$scope.load();
};

}]);



查看完整回答
反对 回复 2019-03-31
?
一只斗牛犬

TA贡献1784条经验 获得超2个赞

用pagination。
<divpagination total-items="totalItems" page="currentPage" first-text="首页"
last-text="尾页" ng-model="currentPage" items-per-page="{{pagesize}}" previous-text="上一页"
next-text='下一页' max-size="maxSize" ng-change="pageChanged()" class="pagination-sm"
boundary-links="true"></div>
控制器里定义totalItems、currentPage、pagesize、maxSize和pageChanged()事件。

查看完整回答
反对 回复 2019-03-31
  • 2 回答
  • 0 关注
  • 646 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信