页面控制器
$scope.demoLists = [ //模拟数据
{name:['hello world','hello world again','why i say hello wrold','i dont know the reason','maybe because i am a developer.','thank you for reading this','why i say thank you','cause this stuff has nothing to do with your angularJs studying','these are just demo sentences.','Do not have any special meanings.','and you still take time to read this row by row','what could i say?','okay.maybe you wanna lenrn how json works.']
}
];
$scope.datanum = $scope.demoLists[].name.length; //获得数据总个数
$scope.pages = Math.ceil($scope.datanum/); //按照每页显示个数据,得到总页数
$scope.pageNum = []; //生成页码,在 html里 ng-repeat 出来
for(var i=;i<$scope.pages;i++){
$scope.pageNum.push(i);
}
$scope.currentPage = ; //设置当前页是
$scope.listsPerPage = ; //设置每页显示 个
$scope.setPage = function(num){ // 当点击页码数字时执行的函数
$scope.currentPage = num; //将当前页 设置为 页码数
}
$scope.prevPage = function(){ //点击上一页执行的函数
if($scope.currentPage > ){
$scope.currentPage--;
}
}
$scope.nextPage = function(){ //点击下一页执行的函数
if ($scope.currentPage < $scope.pages-){
$scope.currentPage++;
}
}
}]);
这中间要说一下,你生成的 pageNum 是从 0 开始的,但真正的 页码 都是从一开始,所以这也就是 html 里 18 行是 num +1 的缘故。