dirPagination不起作用(角JS分页)(dirPagination does not wo

2019-10-20 14:00发布

我试图用dirPagination ,但它不工作。 在行动中看到我的代码: http://plnkr.co/edit/18BxNhHRNyRoI17sBGQF?p=preview

我的代码:

<!DOCTYPE html>
<html ng-app="myApp">
<head>
<link data-require="bootstrap-css@3.1.1" data-semver="3.1.1" rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<script data-require="angular.js@1.3.0-beta.5" data-semver="1.3.0-beta.5" src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script>
<script data-require="jquery@*" data-semver="2.0.3" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script data-require="bootstrap@3.1.1" data-semver="3.1.1" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

<script>
var myApp = angular.module('myApp', [])
    .controller('PsCtrl', ['$scope', function ($scope) {
        $scope.data = [
            {a:1, b:1},
            {a:2, b:2},
            {a:3, b:3}
        ];
    }]);
</script>


<script src="dirPagination.js"></script>
</head>
<body>

<div ng-controller="PsCtrl">
    ItemCount: {{data.length}}
    <ul>
        <li dir-paginate="item in data | itemsPerPage: 2">{{ item }}</li>
    </ul>
    <dir-pagination-controls></dir-pagination-controls>
</div>
</body>
</html>

我只得到这样的输出:

ItemCount: 3
  ⋅

但我希望在底部,这个输出作为第一页分页控件:

ItemCount: 3
⋅ {"a":1,"b":1}
⋅ {"a":2,"b":2}

当我使用<li ng-repeat="item in data">{{ item }}</li>它显示了正确的列表。

我究竟做错了什么?

Answer 1:

所有你需要运行plnkr是包括dirPaginate到你的角模块:

var myApp = angular.module('myApp', ['angularUtils.directives.dirPagination'])

并更改路径在dirpagination.js分页HTML模板:155

templateUrl:  'dirPagination.tpl.html',


Answer 2:

  1. 下载dirPagination.js从这里开始。

  2. 现在包括dirPagination.js到您的网页。

  3. 添加angularUtils.directives.dirPagination你的模块像这样的

var app = angular.module("myApp",['angularUtils.directives.dirPagination']);
  1. 我们使用dir-paginate指令进行分页,添加dir-paginatetr标签
<tr dir-paginate="event in events|orderBy:['id', 't']:true | itemsPerPage: 5">
  1. 添加如下代码,您的网页或任何你想去的地方上的任何地方。
<dir-pagination-controls
                max-size="5"
                direction-links="true"
                boundary-links="true" >
</dir-pagination-controls>


文章来源: dirPagination does not work (Angular JS pagination)