dirPagination does not work (Angular JS pagination)

心已入冬 提交于 2019-12-11 12:08:37

问题


I am trying to use dirPagination but it does not work. See my code in action: http://plnkr.co/edit/18BxNhHRNyRoI17sBGQF?p=preview

My code:

<!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>

I only get this as output:

ItemCount: 3
  ⋅

But I would expect pagination controls at the bottom and this output as a first page:

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

When I use <li ng-repeat="item in data">{{ item }}</li> it shows the correct list.

What am I doing wrong?


回答1:


All you need to run your plnkr is to include dirPaginate into your angular module:

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

And change path to pagination HTML template in dirpagination.js:155 to

templateUrl:  'dirPagination.tpl.html',



回答2:


  1. Download dirPagination.js from here.

  2. Now include dirPagination.js to your page.

  3. Add angularUtils.directives.dirPagination in your module like this

var app = angular.module("myApp",['angularUtils.directives.dirPagination']);
  1. We use dir-paginate directive for pagination ,add dir-paginate in tr tag
<tr dir-paginate="event in events|orderBy:['id', 't']:true | itemsPerPage: 5">
  1. Add below given code anywhere on your page or where ever you want.
<dir-pagination-controls
                max-size="5"
                direction-links="true"
                boundary-links="true" >
</dir-pagination-controls>


来源:https://stackoverflow.com/questions/25027050/dirpagination-does-not-work-angular-js-pagination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!