1.官网链接  https://github.com/esvit/ng-table#4.0.0

2.安装ngTable后,一定要记得先注册到自己的项目

.module('pttengApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'mgcrea.ngStrap',
'ngTable'
])

3.编辑使用ngTable的controller  JS文件

angular.module('pttengApp')
.controller('ArticlelistCtrl', function ($scope,$location,ArticleService,NgTableParams) {/*NgTableParams一定要放在正确的位置*/
var self=this;
var simplelist=ArticleService.getAll(); /*这个就是传给NgTableParams的数据,也就是我们table里要显示的各行数据*/
self.tableParams=new NgTableParams({ count: 5},{counts: [5, 10, 20],dataset:simplelist});
self.selectedPageSizes=self.tableParams.settings().counts;
self.availablePageSizes = [5, 10, 15, 20, 25, 30, 40, 50, 100];
self.changePage = changePage; function changePage(nextPage){
self.tableParams.page(nextPage);
}
function changePageSize(newSize){
self.tableParams.count(newSize);
}
function changePageSizes(newSizes){
// ensure that the current page size is one of the options
if (newSizes.indexOf(self.tableParams.count()) === -1) {
newSizes.push(self.tableParams.count());
newSizes.sort();
}
self.tableParams.settings({ counts: newSizes});
}
});

4.html部分的书写

<table ng-table="articlelist.tableParams" show-filter="true" class="table table-hover">/*黑色高亮的就是使用ngTable的controller name*/
<tr ng-repeat="article in $data">/*强调这个$data就是说这个很关键,这个data是tableParams里的data数组,也就是通过dataset添加进去要显示的各行数据*/
<td>{{article.id}}</td>
<td>{{article.name}}</td>
<td>{{article.type}}</td>
<td>{{article.createtime}}</td>
<td>{{article.lastmodifiedtime}}</td>
</tr>
</table>

*************************

利用 yo angular:service Article-Service创建一个服务,生成的js文件里面可以创建一个构造函数,属性是JSON数据,方法就用来返回这些数据,然后我们就可以利用这个服务提供的数据进行前端功能的测试啦(在需要用到他的controller里面注人这个service,比如

.controller('ArticlelistCtrl', function ($scope,$location,ArticleService,NgTableParams) {

'use strict';

/**
* @ngdoc service
* @name pttengApp.ArticleService
* @description
* # ArticleService
* Service in the pttengApp.
*/
angular.module('pttengApp')
.service('ArticleService', function () {
// AngularJS will instantiate a singleton by calling "new" on this function
var articles = [
{
"id": "1",
"name": "行业动态",
"type": "行业",
"createtime": "2017-05-06",
"lastmodifiedtime": "2017-05-06",
"createuser": "admin",
"status": "0",
"operation": "delete"
},
{
"id": "2",
"name": "JSON",
"type": "语法",
"createtime": "2017-05-06",
"lastmodifiedtime": "2017-05-06",
"createuser": "admin",
"status": "0",
"operation": "delete"
}
]; return {
getAll: function () {
return articles;
},
getById: function () {
for (var i = 0; i < articles.length; i++) {
if (articles[i].id === id) {
return articles[i];
}
}
return null;
}
}; });

最新文章

  1. Linux下Nginx+Tomcat负载均衡和动静分离配置要点
  2. Android 自动生成的R类
  3. Java多线程--wait和join
  4. OSGI.NET 学习笔记(一)
  5. 【转】使用NetBeans和Eclipse开发PHP应用程序
  6. Android 高级UI设计笔记03:使用ListView实现左右滑动删除Item
  7. rtsp的东西
  8. npm note
  9. Java之GC
  10. [JSOI2007]祖码Zuma
  11. url路由配置以及渲染方式
  12. SwipeBackLayout 右滑退出Activity
  13. python文件读和写
  14. 【算法】解析IEEE 754 标准
  15. [Algorithm]Algorithm章1 排序算法
  16. HDU1160(KB12-J DP)
  17. Pandas Learning
  18. [转]NuGet 包升级
  19. part1:6-Linux文本编辑器vi
  20. python numpy数组中的复制问题

热门文章

  1. 远程连接阿里云服务器出现&quot;远程桌面,身份验证错误:要求的函数不受支持&quot;解决办法
  2. 09-04 java 接口
  3. MATLAB下数组随机打乱顺序的方法
  4. centos 7 hadoop的安装和使用
  5. web工程迁移---jboss5迁移到jboss6
  6. 读书笔记(03) - 性能 - JavaScript高级程序设计
  7. 如何在Notepad++里正确设置java环境(图文环境)
  8. 第三方登录:微信扫码登录(OAuth2.0)
  9. 两台Mysql数据库数据同步实现
  10. MySQL进程-状态等参数详解