首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angularjs-Bootstrap分页

Angularjs-Bootstrap分页
EN

Stack Overflow用户
提问于 2015-08-24 14:15:10
回答 2查看 356关注 0票数 0

我正在尝试建立分页使用Bootstrap pager在我的angularjs代码,但下一步按钮总是看起来是disabled.When,我运行相同的代码与常量数据,它是工作的fine.In控制器,我正在获取数据显示通过Rest API和数据是从API返回。

代码语言:javascript
复制
<div ng-app="manageApp">
    <div ng-controller="ManageCampaignController" class="bs-example">
        <div>
            <div class="btn-group inline-content">
               <label class="btn btn-primary" ng-model="existingCampaigns.manageMode" btn-radio="'Current'">Current</label>
               <label class="btn btn-primary" ng-model="existingCampaigns.manageMode" btn-radio="'Other'" >Other</label>
            </div>
         </div>
         <div ng-show="existingCampaigns.manageMode=='Current'">
         {{totalItems}}{{currentPage}}
        <pager total-items="3" ng-model="currentPage"></pager>
        <table class="table" style="width:800px;">
            <thead class="row">
                <th class="col-md-1">
                    Name
                </th>
                <th class="col-md-1">
                    Start Date
                </th>
                <th class="col-md-1">
                    End Date
                </th>
                <th class="col-md-1">
                    Status
                </th>
                <th class="col-md-3">
                    Actions
                </th>
            </thead>
            <tbody>
                <tr ng-repeat= "item in existingCampaigns | limitTo:1">
                    <td>
                        {{item.name}}
                    </td>
                    <td>
                        {{item.startDate}}
                    </td>
                    <td>
                        {{item.endDate}}
                    </td>
                    <td>
                        {{item.status}}
                    </td>
                    <td>
                        <input class="btn btn-default" type="button" value="View"/>  
                        <input class="btn btn-default" type="button" value="Edit"/> 
                        <input class="btn btn-default" type="button" value="Pause"/> 
                        <input class="btn btn-default" type="button" value="Archive"/>               
                    </td>
                </tr>
            </tbody>
        </table>
        </div>
    </div>

</div>


var manageApp = angular.module('manageApp',['ngAnimate', 'ui.bootstrap']);
manageApp.controller('ManageCampaignController', function($scope, $http, $log) {
    $scope.currentPage = 1;
    $scope.existingCampaigns = {};
    $http.get('http://localhost:8080/campaign_manager/campaign').success(function (data){
        $log.log('data' + data);
        $scope.existingCampaigns = data;
        $scope.totalItems = $scope.existingCampaigns.length;
        $log.log('totalItems' + $scope.totalItems);
        $scope.setPage = function (pageNo) {
            $scope.currentPage = pageNo;
        };

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

    });


});
manageApp.filter('startFrom', function() {
    return function(input, start) {
       if (!input || !input.length) { return; }
        start = +start; //parse to int
        return input.slice(start);
    }
});
EN

回答 2

Stack Overflow用户

发布于 2015-08-24 16:55:58

我不确定这是不是你想要的,但是要寻呼引导,你可以使用下面这样的东西。它可能运行得更好:

html:

代码语言:javascript
复制
<pagination page="currentPage" max-size="nbOfPages" total-items="totalItems" items-per-page="nbItemsPerPage"></pagination>

控制器:

代码语言:javascript
复制
$scope.currentPage = 1;
$scope.existingCampaigns = {};
$http.get('http://localhost:8080/campaign_manager/campaign').success(function (data){
        $log.log('data' + data);
        $scope.existingCampaigns = data;
        //pagination
        $scope.totalItems = $scope.existingCampaigns.length;
        $scope.nbItemsPerPage = 2; //You can modify this value like you want 
        $scope.nbOfPages = Math.ceil($scope.totalItems / $scope.numPerPage);

        $log.log('totalItems' + $scope.totalItems);
        $scope.setPage = function (pageNo) {
            $scope.currentPage = pageNo;
        };

如果这对你有帮助,请随时通知我。附言:如果你可以,创建一个管道,这将更容易帮助你。

票数 0
EN

Stack Overflow用户

发布于 2015-08-25 14:52:16

我通过myself.Thing发现我需要使用Bootstrap的每页项目数属性。

代码语言:javascript
复制
<pagination ng-model="currentPage" total-items="total" items-per-page="numPerPage"></pagination>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32175543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档