dirPagination不起作用(Angular JS分页)

时间:2014-07-30 00:30:59

标签: angularjs angularjs-directive dirpagination

我正在尝试使用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>时,它会显示正确的列表。

我做错了什么?

1 个答案:

答案 0 :(得分:9)

运行plnkr所需的只是将dirPaginate包含在角度模块中:

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

将路径更改为dirpagination.js:155中的分页HTML模板

templateUrl:  'dirPagination.tpl.html',