Detailed example of Angular Js paging display data
When working on projects, we often use paging to display data. In fact, the principle is very simple: every time you click on a (next/previous) page, a request is sent to the background to obtain relevant JSON data. What I am demonstrating here is that I Each request will be passed to the background with two parameters (pageSize – the data to be displayed on each page, pageNo – the current page number)
HTML related code:
<p id='demo' ng-app='myApp' ng-controller='myCtrl'> <table> <thead> <th>序号</th> <th>操作人</th> <th>类别</th> <th>电话</th> <th>金额</th> <th>操作时间</th> </thead> <tbody> <tr ng-repeat="item in items"> <td>{{$index+1}}</td> <td>{{item.operator}}</td> <td>{{item.type}}</td> <td>{{item.tell}}</td> <td>{{item.price}}</td> <td>{{item.operateTime}}</td> </tr> </tbody> </table> <p class="page"> <span class="nextPage" ng-click="nextPage()">下一页</span> <span class="prevPage" ng-click="lastPage()">上一页</span> <span>{{cur}}/{{totalPage}} 页 共 {{totalNum}} 条记录</span> </p> </p>
CSS code will not be pasted It’s up, everyone can add it by themselves;
JS code:
var params={ pageSize:10, pageNo:1 };var curPage=1;var app = angular.module('myApp', []); app.controller('myCtrl', function($scope,$http) { init($scope,$http); })function search($http,$scope){ params.pageNo=pageNo; $http({ method: 'GET', url:后台接口地址, params:params }).then(function successCallback(response) { // 数据总条数 $scope.totalNum = response.data.totalNum; // 数据总页数 $scope.totalPage = response.data.totalPage; // 数据当前页 $scope.cur = curPage; // 列表详细数据 var content = response.data.contents; for(var i in content){ // 数据操作人 content[i].operator= content[i].operator; // 数据电话 content[i].tell= content[i].tell; // 数据类别 content[i].type = content[i].type; // 数据操作时间 content[i].operateTime = content[i].createTime; // 数据价格 content[i].price = content[i].price; } $scope.items = content; }, function errorCallback(response) { // 请求失败执行代码 if(response!=null) error(response) }); }function init($scope,$http){ search($http,$scope); $scope.nextPage=function(){ nextPage($http,$scope); }; $scope.lastPage=function(){ lastPage($http,$scope); }; }// 点击上一页function lastPage($http,$scope){ if(curPage>1){ curPage--; search($http,$scope); } }// 点击下一页function nextPage($http,$scope){ if(curPage<totalPage){ curPage++; search($http,$scope); } } **注意**1、如果在你的项目里有根据数据前面的序号来删除某条数据,建议看下这篇博文[Angular Js中$index的小心使用](http://blog.csdn.net/renfufei/article/details/43061877)2、如果你的项目后台传过来的数据没有经过处理是全部的数据可以参考这篇博文[Angular Js表格分页](http://www.cnblogs.com/smilecoder/p/6519833.html)
Next/Previous page), send a request to the background to obtain relevant JSON data. What I demonstrate here is that each request will be passed to the background with two parameters (pageSize – the data to be displayed on each page, pageNo – the current page number). This Share the relevant content in this article;
HTML related code:<p id='demo' ng-app='myApp' ng-controller='myCtrl'> <table> <thead> <th>序号</th> <th>操作人</th> <th>类别</th> <th>电话</th> <th>金额</th> <th>操作时间</th> </thead> <tbody> <tr ng-repeat="item in items"> <td>{{$index+1}}</td> <td>{{item.operator}}</td> <td>{{item.type}}</td> <td>{{item.tell}}</td> <td>{{item.price}}</td> <td>{{item.operateTime}}</td> </tr> </tbody> </table> <p class="page"> <span class="nextPage" ng-click="nextPage()">下一页</span> <span class="prevPage" ng-click="lastPage()">上一页</span> <span>{{cur}}/{{totalPage}} 页 共 {{totalNum}} 条记录</span> </p> </p>
The CSS code will not be posted, please add it yourself; JS code:
var params={ pageSize:10, pageNo:1 };var curPage=1;var app = angular.module('myApp', []); app.controller('myCtrl', function($scope,$http) { init($scope,$http); })function search($http,$scope){ params.pageNo=pageNo; $http({ method: 'GET', url:后台接口地址, params:params }).then(function successCallback(response) { // 数据总条数 $scope.totalNum = response.data.totalNum; // 数据总页数 $scope.totalPage = response.data.totalPage; // 数据当前页 $scope.cur = curPage; // 列表详细数据 var content = response.data.contents; for(var i in content){ // 数据操作人 content[i].operator= content[i].operator; // 数据电话 content[i].tell= content[i].tell; // 数据类别 content[i].type = content[i].type; // 数据操作时间 content[i].operateTime = content[i].createTime; // 数据价格 content[i].price = content[i].price; } $scope.items = content; }, function errorCallback(response) { // 请求失败执行代码 if(response!=null) error(response) }); }function init($scope,$http){ search($http,$scope); $scope.nextPage=function(){ nextPage($http,$scope); }; $scope.lastPage=function(){ lastPage($http,$scope); }; }// 点击上一页function lastPage($http,$scope){ if(curPage>1){ curPage--; search($http,$scope); } }// 点击下一页function nextPage($http,$scope){ if(curPage<totalPage){ curPage++; search($http,$scope); } } **注意**1、如果在你的项目里有根据数据前面的序号来删除某条数据,建议看下这篇博文[Angular Js中$index的小心使用](http://blog.csdn.net/renfufei/article/details/43061877)2、如果你的项目后台传过来的数据没有经过处理是全部的数据可以参考这篇博文[Angular Js表格分页](http://www.cnblogs.com/smilecoder/p/6519833.html)
Related recommendations:PHP example code: AJAX paging display data_PHP tutorial
jQuery+Ajax+PHP+Mysql implementation of paging display data example explanation_jquery
The above is the detailed content of Detailed example of Angular Js paging display data. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Angular.js is a freely accessible JavaScript platform for creating dynamic applications. It allows you to express various aspects of your application quickly and clearly by extending the syntax of HTML as a template language. Angular.js provides a range of tools to help you write, update and test your code. Additionally, it provides many features such as routing and form management. This guide will discuss how to install Angular on Ubuntu24. First, you need to install Node.js. Node.js is a JavaScript running environment based on the ChromeV8 engine that allows you to run JavaScript code on the server side. To be in Ub

Windows operating system is one of the most popular operating systems in the world, and its new version Win11 has attracted much attention. In the Win11 system, obtaining administrator rights is an important operation. Administrator rights allow users to perform more operations and settings on the system. This article will introduce in detail how to obtain administrator permissions in Win11 system and how to effectively manage permissions. In the Win11 system, administrator rights are divided into two types: local administrator and domain administrator. A local administrator has full administrative rights to the local computer

Detailed explanation of division operation in OracleSQL In OracleSQL, division operation is a common and important mathematical operation, used to calculate the result of dividing two numbers. Division is often used in database queries, so understanding the division operation and its usage in OracleSQL is one of the essential skills for database developers. This article will discuss the relevant knowledge of division operations in OracleSQL in detail and provide specific code examples for readers' reference. 1. Division operation in OracleSQL

The default display behavior for components in the Angular framework is not for block-level elements. This design choice promotes encapsulation of component styles and encourages developers to consciously define how each component is displayed. By explicitly setting the CSS property display, the display of Angular components can be fully controlled to achieve the desired layout and responsiveness.

The modulo operator (%) in PHP is used to obtain the remainder of the division of two numbers. In this article, we will discuss the role and usage of the modulo operator in detail, and provide specific code examples to help readers better understand. 1. The role of the modulo operator In mathematics, when we divide an integer by another integer, we get a quotient and a remainder. For example, when we divide 10 by 3, the quotient is 3 and the remainder is 1. The modulo operator is used to obtain this remainder. 2. Usage of the modulo operator In PHP, use the % symbol to represent the modulus

Detailed explanation of Linux system call system() function System call is a very important part of the Linux operating system. It provides a way to interact with the system kernel. Among them, the system() function is one of the commonly used system call functions. This article will introduce the use of the system() function in detail and provide corresponding code examples. Basic Concepts of System Calls System calls are a way for user programs to interact with the operating system kernel. User programs request the operating system by calling system call functions

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

As a programming language widely used in the field of software development, C language is the first choice for many beginner programmers. Learning C language can not only help us establish the basic knowledge of programming, but also improve our problem-solving and thinking abilities. This article will introduce in detail a C language learning roadmap to help beginners better plan their learning process. 1. Learn basic grammar Before starting to learn C language, we first need to understand the basic grammar rules of C language. This includes variables and data types, operators, control statements (such as if statements,
