AngularJS分页类型错误:无法读取属性';切片';未定义的
我收到一条错误消息AngularJS分页类型错误:无法读取属性';切片';未定义的,angularjs,pagination,angular-ui-bootstrap,slice,Angularjs,Pagination,Angular Ui Bootstrap,Slice,我收到一条错误消息TypeError:在尝试使用引导分页时,无法读取未定义的的属性“slice”。我认为错误是由于尝试在ng repeat中的项上应用.slice()方法时出现了范围问题 我已经包含了我认为问题发生的代码。我一直在用这篇文章作为解决问题的指南 Controllers.js: defaultPage = angular.module('DefaultPage', ['ui.bootstrap']); defaultPage.controller('DefaultControlle
TypeError:在尝试使用引导分页时,无法读取未定义的
的属性“slice”。我认为错误是由于尝试在ng repeat
中的项上应用.slice()
方法时出现了范围问题
我已经包含了我认为问题发生的代码。我一直在用这篇文章作为解决问题的指南
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>
-
您无法分割不存在的内容,请先尝试定义项目。我想从HTML中的ng repeat中分割“项目”。我该怎么做?您可以在repeat上执行ng if
,并将其与$index
进行比较,或者您可以实现一个接受start和end参数的过滤器,并进行如下比较:way@paul147我是Angular方面的新手,我已经创建了过滤器,但没有使用ng if。我已经研究过使用过滤器,但我不确定如何将其与controller.js中的ui引导分页脚本结合起来。您应该在范围内定义项。您只是说要对items数组进行切片,但没有名为$scope.items的数组。问题出在控制器内部。下面的链接解决了我的问题