Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular-ui/bootstrap: pagination not rendered (missing styles?)

I'm new to angular-ui and playing with it. I'm trying to use the pagination directive (http://angular-ui.github.io/bootstrap/#/pagination), but it seems I'm missing some styles as I just see the unordered list rendered, rather than the expected pager UI. I included the following resources, in this order:

1) the latest (RC) bootstrap CSS: http://blog.netdna.com/opensource/bootstrapcdn/bootstrapcdn-now-serving-3-0-0-rc1/

2) angular JS: http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js

3) angular-ui/bootstrap: I include from https://github.com/angular-ui/bootstrap/tree/gh-pages the file ui-bootstrap-tpls-0.4.0.js

My HTML sample body:

<body ng-app="Test">
<div ng-controller="PaginationDemoCtrl" class="well well-small">
    <pagination boundary-links="true" num-pages="noOfPages" current-page="currentPage" class="pagination-small" previous-text="'&lsaquo;'" next-text="'&rsaquo;'" first-text="'&laquo;'" last-text="'&raquo;'"></pagination>
</div>
<script>
var PaginationDemoCtrl = function ($scope) {
  $scope.noOfPages = 7;
  $scope.currentPage = 4;
  $scope.maxSize = 5;  
  $scope.setPage = function (pageNo) {
    $scope.currentPage = pageNo;
  };
};
var app = angular.module("Test", ["ui.bootstrap"]);
</script>
</body>
like image 213
Naftis Avatar asked Aug 01 '13 12:08

Naftis


4 Answers

I was able to fix styling by following quick source code change:

in your ui-bootstrap file (mine was named ui-bootstrap-tpls-0.6.0.min.js) find following text:

<div class="pagination"><ul>

and then add class="pagination" to <ul> so it looks like this

<div class="pagination"><ul class="pagination">
like image 70
Valera Avatar answered Oct 19 '22 23:10

Valera


I had an issue with pagination when I updated my angular-bootstrap version. It seems that they have changed the way we should use the directive.

before

<uib-pagination
    total-items="pagination.total_entries"
    ng-model="pagination.current_page"
    ng-change="pageChanged()">
</uib-pagination>

after

<ul uib-pagination
    total-items="pagination.total_entries"
    ng-model="pagination.current_page"
    ng-change="pageChanged()">
</ul>
like image 44
Nirav Gandhi Avatar answered Oct 19 '22 22:10

Nirav Gandhi


It's not your fault. Turns out angular UI is not 100% compatible with bootstrap 3 just yet. Most things work, but you can see the status in this issue: Support bootstrap 3.0. I don't have the time to dive into this particular issue right now, but since all the styles are missing rather than some slightly broken thing, and all the functionality is fine, I bet it's an easy fix (renaming a class, etc). Meanwhile, you should either:

  1. Switch to old boostrap
  2. Write it yourself
  3. Use the <pager> with new boostrap - I just tested it, and it works fine. So instead of <pagination> you want <pager>. A few fewer buttons but works for my purposes.

For instance:

<pager num-pages="numPages()" current-page="currentPage"></pager>

Hope that helps!

like image 27
Eli Albért Avatar answered Oct 19 '22 23:10

Eli Albért


I have the same issue and I changed the template to address the changes in Bootstrap 3:

angular.module("template/pagination/pagination.html", []).run(["$templateCache", function($templateCache) {
  $templateCache.put("template/pagination/pagination.html",
    "<ul class=\"pagination\">\n" +
    "  <li ng-repeat=\"page in pages\" ng-class=\"{active: page.active, disabled: page.disabled}\"><a ng-click=\"selectPage(page.number)\">{{page.text}}</a></li>\n" +
    "</ul>\n" +
    "");
}]);

Just add the above wherever you created your modules.

like image 35
mlim1972 Avatar answered Oct 19 '22 22:10

mlim1972