【问题标题】:AngularJS Pagination With Bootstrap Not Displaying Next/Prev Buttons带有引导程序的AngularJS分页不显示下一个/上一个按钮
【发布时间】:2018-09-12 01:11:59
【问题描述】:

我正在尝试使用 AngularJS 和 Bootstrap 对通过 JSON 获得的数据进行分页。它的工作原理是它只显示我想要的每页数量,但 Next/Prev 和编号按钮根本不显示。在我的编辑器(Notepad++)中似乎甚至无法识别分页标签,我不确定这是否与它有关。我目前正在IE中进行测试。感谢您提供任何帮助,因为我已经坚持了一段时间 - 谢谢!

这是我的 HTML/JS:

<!DOCTYPE html>
<html ng-app="myApp">
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>   
    <script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>NES- Home</title>
    <link rel="stylesheet" type="text/css" href="main.css"/>
</head>

<body onload="getUrl()">
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="Home.html"> Admin</a>
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li><a href="Users.html">Users</a></li>
                </ul>
                <p class="nav navbar-text navbar-right"></p>
            </div>
        </div>
    </div>

    <form class="form-inline">
        <div class="form-group">
            <label >Search</label>
            <input type="text" ng-model="search.Username" class="form-control" placeholder="Search">
        </div>
    </form>

    <table class="table" ng-controller="myCtrl">
      <tr>
        <th ng-click="sort('Username')">Username</th>
        <th ng-click="sort('Domain')">Domain</th>
        <th ng-click="sort('GivenName')">Given Name</th>
        <th ng-click="sort('Surname')">Surname</th>
      </tr>
      <tr ng-repeat="user in users.slice(((currentPage-1)*itemsPerPage), ((currentPage)*itemsPerPage))|orderBy:sortKey:reverse|filter:search">
        <td>{{user.Username}}</td>
        <td>{{user.Domain}}</td>
        <td>{{user.GivenName}}</td>
        <td>{{user.Surname}}</td>
      </tr>

    </table>

    <pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()" class="pagination-sm" items-per-page="itemsPerPage"></pagination>

    <iframe id="iframe" src="Index.html" style="display:none"></iframe>

    <script>

        function getUrl() {
            var uri= document.getElementById('iframe').contentWindow.document.getElementById('apiUri').value;
            server = uri + (uri.last === "/" ? "" : "/");
        }   

        var server; 
        var app = angular.module('myApp', []);

        app.controller('myCtrl', function($scope, $http) {
            $http({
                method : "GET",
                url : URL
            }).then(function mySuccess(response) {
                $scope.users = response.data;
                $scope.viewby = 5;
                $scope.totalItems = $scope.users.length;
                $scope.currentPage = 1;
                $scope.itemsPerPage = $scope.viewby;
                $scope.maxSize = 5; //Number of pager buttons to show

            });

            $scope.sort = function(keyname){
                $scope.sortKey = keyname;   //set the sortKey to the param passed
                $scope.reverse = !$scope.reverse; //if true make it false and vice versa
            }

              $scope.setPage = function (pageNo) {
    $scope.currentPage = pageNo;
  };

  $scope.pageChanged = function() {
    console.log('Page changed to: ' + $scope.currentPage);
  };

$scope.setItemsPerPage = function(num) {
  $scope.itemsPerPage = num;
  $scope.currentPage = 1; //reset to first page
}
        });

    </script>

</body>
</html>

这是我遵循的示例,效果很好:http://embed.plnkr.co/eheFSh/

【问题讨论】:

  • 您能否对当前代码进行 plnkr 以重现该问题?

标签: javascript angularjs json twitter-bootstrap pagination


【解决方案1】:

ui-bootstrap 需要 Angular 和 Bootstrap CSS 文件作为依赖项。看起来您错过了在代码中链接引导 css 文件。

<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">

【讨论】:

  • 谢谢,我加了,可惜问题依旧。
猜你喜欢
  • 1970-01-01
  • 2020-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多