我收到錯誤消息「TypeError:嘗試使用Bootstrap分頁時無法讀取屬性」切片「未定義」。我相信這個錯誤發生在範圍問題上,同時試圖在ng-repeat中的'items'上應用.slice()方法。我已經包含了我認爲問題正在發生的代碼。我一直在使用這個職位AngularJS pagination and Cannot read property 'slice' of undefined作爲解決我遇到的問題的指南。AngularJS分頁類型錯誤:無法讀取未定義的屬性「切片」
Controllers.js:
defaultPage = angular.module('DefaultPage', ['ui.bootstrap']);
defaultPage.controller('DefaultController', ['$scope', '$http', function ($scope, $http) {
$scope.data = {};
$scope.totalItems = $scope.ctrl.info.length;
//console.log($scope.ctrl.info.length)
$scope.itemsPerPage = 25;
$scope.currentPage = 1;
$scope.max = "3";
$scope.pageCount = function() {
var begin = (($scope.currentPage - 1) * $scope.itemsPerPage);
//console.log(begin)
var end = begin + $scope.itemsPerPage;
//console.log(end)
$scope.totalItems = $scope.items.slice(begin, end);
console.log($scope.items)
};
}]);
HTML:
<div class="main" ng-controller="DefaultController as ctrl">
<div class="search">
<h1 class="shadow"></h1>
<div class="searchbox">
<i class="fa fa-search"></i>
<input ng-model="query" placeholder="Search Issue Title or Case #" autofocus>
</div>
</div>
<ul class="channellist">
<li ng-repeat="items in ctrl.info | filter: query | filter: issue" class="channel cf">
<a ng-href="#/issues/{{ctrl.info.indexOf(items)}}">
<img ng-src="{{items.user.avatar_url}}" alt="channel logo for {{items.user.avatar_url}}" />
<div class="info">
<h2 class="userName">{{items.user.login}}</h2>
<h4 class="case">case: #{{items.number}}</h4>
<h4 class="case">issue status: {{items.state}}</h4>
<div class="main">
<h3 class="title">{{items.title}}</h3>
<p class="body">{{items.body}}</p>
</div>
<div class="label_info">
<ul>
<li class="mark">Created:</li>
<li class="mark"> {{items.created_at}}
</li>
<li class="mark">Updated:</li>
<li class="mark"> {{items.updated_at}}</li>
</ul>
</div>
</div>
</a>
</li>
<uib-pagination boundary-links="true" max-size="max" items-per-page="itemsPerPage" total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()"></uib-pagination>
</ul>
</div>
下面的鏈接解決了我的問題http://stackoverflow.com/questions/25723455/custom-filter-giving-cannot-read-property-slice-of-undefined-in-angularjs –