【问题标题】:Angular-bootstrap pagination gives undefined function errorAngular-bootstrap 分页给出未定义的函数错误
【发布时间】:2015-03-14 16:40:34
【问题描述】:

我正在尝试使用 angular-bootstrap 分页页脚

我得到了错误

 TypeError: undefined is not a function
    at Object.fn (http://localhost:3000/lib/angular-bootstrap/ui-bootstrap-tpls.js:2265:5)
    at Scope.$get.Scope.$digest (http://localhost:3000/lib/angular/angular.js:12650:29)
    at Scope.$get.Scope.$apply (http://localhost:3000/lib/angular/angular.js:12915:24)
    at done (http://localhost:3000/lib/angular/angular.js:8450:45)
    at completeRequest (http://localhost:3000/lib/angular/angular.js:8664:7)
    at XMLHttpRequest.xhr.onreadystatechange (http://localhost:3000/lib/angular/angular.js:8603:11)angular.js:10126 (anonymous function)angular.js:7398 $getangular.js:12669 $get.Scope.$digestangular.js:12915 $get.Scope.$applyangular.js:8450 doneangular.js:8664 completeRequestangular.js:8603 xhr.onreadystatechange

ui-bootstrap-tpls.js:2265 行是“setNumPages”

$scope.$watch('totalPages', function(value) {
  setNumPages($scope.$parent, value); // Readonly variable

  if ( $scope.page > value ) {
    $scope.selectPage(value);
  } else {
    ngModelCtrl.$render();
  }
});

我使用 bower 安装了 angular-bootstrap 并包含

'public/lib/angular-bootstrap/ui-bootstrap-tpls.js',

当我在 angular-bootstrap repo 中搜索函数 setNumPages 时,我在

中找到了它
src/pagination/pagination.js 

如何确保 pagination.js 也加载到我的浏览器中。我没有在我的库中找到 pagination.js。我关注了How to do paging in AngularJS?

【问题讨论】:

  • 我的猜测 - setNumPages 设置为 here$parse($attrs.numPages).assign 或 noop。后者不应该给你你看到的错误,所以我猜前者没有返回一个有效的函数。您能否为 num-pages 属性提供错误的表达式?也许试试像3 这样的简单值,看看是否可以清除它。
  • 这可能会为您指明正确的方向:stackoverflow.com/questions/26141818/…

标签: javascript angularjs twitter-bootstrap pagination


【解决方案1】:

尝试将 numPages 更改为属性而不是函数:

$scope.numPages = Math.ceil($scope.todos.length / $scope.numPerPage);

【讨论】:

    【解决方案2】:

    我有同样的错误,我解决了这个问题 ->

    UI 中的第一个:

    <pagination
      total-items="vm.pagination.totalItems"
      items-per-page="vm.pagination.itemsPerPage"
      ng-model="vm.pagination.currentPage"
      current-page="vm.pagination.currentPage"
      boundary-links="true">
    </pagination>
    

    Ctrl 中的第二个:

    var vm = this, //controllerAs: 'vm'
        itemsPerPage = 10;
    vm.pagination = {
       currentPage: 1,
       itemsPerPage: itemsPerPage,
       totalItems: vm.alarms.length,
       numPages: Math.ceil(vm.alarms.length / itemsPerPage)
     };
    
     $scope.$watch('vm.pagination.currentPage', function() {
        var begin = ((vm.pagination.currentPage - 1) * vm.pagination.itemsPerPage),
            end = begin + vm.pagination.itemsPerPage;
        vm.filterAlarms = vm.alarms.slice(begin, end);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      • 2015-03-17
      • 2020-04-15
      • 1970-01-01
      • 2014-12-26
      • 2015-02-28
      • 2023-03-10
      相关资源
      最近更新 更多