การแบ่งหน้า 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();
  }
});

ฉันติดตั้ง angular-bootstrap โดยใช้ bower และรวมไว้ด้วย

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

เมื่อฉันค้นหาฟังก์ชัน setNumPages ใน repo เชิงมุมบูตสแตรป ฉันพบมันใน

src/pagination/pagination.js 

ฉันจะแน่ใจได้อย่างไรว่า pagination.js ถูกโหลดลงในเบราว์เซอร์ของฉันแล้ว ฉันไม่พบ pagination.js ใน lib ของฉัน ฉันติดตาม จะทำเพจใน AngularJS ได้อย่างไร


person raju    schedule 16.01.2015    source แหล่งที่มา
comment
ฉันเดา - setNumPages ถูกตั้งค่าไว้ ที่นี่ ถึง $parse($attrs.numPages).assign หรือ noop อย่างหลังไม่ควรให้ข้อผิดพลาดที่คุณเห็น ดังนั้นฉันเดาว่าอันแรกจะไม่ส่งคืนฟังก์ชันที่ถูกต้อง คุณช่วยระบุนิพจน์ที่ไม่ดีสำหรับแอตทริบิวต์ num-pages ได้ไหม อาจลองใช้ค่าตายง่ายเช่น 3 แล้วดูว่าจะชัดเจนหรือไม่   -  person Bungle    schedule 16.01.2015
comment
สิ่งนี้อาจชี้คุณไปในทิศทางที่ถูกต้อง: stackoverflow.com/questions/26141818/   -  person Bungle    schedule 16.01.2015


คำตอบ (2)


ลองเปลี่ยน numPages เป็นคุณสมบัติแทนฟังก์ชัน:

$scope.numPages = Math.ceil($scope.todos.length / $scope.numPerPage);
person ST7    schedule 25.03.2015

ฉันมีข้อผิดพลาดเดียวกันและฉันแก้ไขปัญหานี้ ->

ครั้งแรกใน 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);
});
person eugene.sushilnikov    schedule 08.04.2015