【问题标题】:Angular UI Bootstrap pagination - show first 12 records in ng-repat on inital page loadAngular UI Bootstrap 分页 - 在初始页面加载时在 ng-repeat 中显示前 12 条记录
【发布时间】:2017-02-12 15:36:09
【问题描述】:

请参阅此plunker,了解我的问题的工作示例。

当我单击分页页码但最初没有加载第一页(第一组记录)的数据时,分页正在工作。当你点击一个数字时,它就可以正常工作了。

请注意:上面的 plunker 只是 SO 的一个演示,我的实际项目更复杂,所以我不能摆脱 dataService 等。

var app = angular.module('plunker', ['ui.bootstrap.tpls', 'ui.bootstrap.pagination']);

app.controller('MainCtrl', function($scope, dataService) {
  $scope.data = [];

  dataService.getAll()
            .then(function (response) {
                // Success
                $scope.data = response.data;
                $scope.totalItems = $scope.data.length;
            }, function (data, status, header, config) {
                // Failure
            });

  $scope.itemsPerPage = 12;
  $scope.currentPage = 1;

  $scope.pageCount = function () {
    return Math.ceil($scope.data/ $scope.itemsPerPage);
  };

  $scope.$watch('currentPage + itemsPerPage', function () {
    var begin = (($scope.currentPage - 1) * $scope.itemsPerPage),
    end = begin + $scope.itemsPerPage;

    $scope.filtered = $scope.data.slice(begin, end);
  });

});

//数据服务

(function() {

"use strict";

angular.module("plunker").factory("dataService", dataService);

function dataService($http) {

     return {
        getAll: getAll
     }

     function getAll() {

        return $http.get("http://api.scb.se/OV0104/v1/doris/en/ssd");
    }
}

})();

【问题讨论】:

    标签: angularjs pagination angularjs-ng-repeat angular-ui-bootstrap


    【解决方案1】:

    更新插件:http://plnkr.co/edit/2yHEukhKZcFplmJaFv0P

    新增功能updateView()

    一旦数据首先加载到你的手表中,就会调用这个函数

    【讨论】:

      猜你喜欢
      • 2015-03-10
      • 2018-08-07
      • 2014-10-16
      • 2017-01-24
      • 1970-01-01
      • 2015-03-09
      • 2016-12-25
      • 1970-01-01
      • 2017-05-25
      相关资源
      最近更新 更多