我正在使用Angular Bootstrap UI的分页指令的一个相当简单的实现,但我一直收到一个无法确定的错误。下面是相关的代码片段:
<ul>
<li ng-repeat="todo in filteredIdeas">
{{todo}}
</li>
</ul>
<pagination ng-model="currentPage" total-items="totalIdeas"></pagination>
下面是我的$scope在控制器中的相关部分:
// Set watch on pagination numbers
$scope.$watch('currentPage + numPerPage', function() {
var begin = (($scope.currentPage - 1) * $scope.numPerPage);
var end = begin + $scope.numPerPage;
$scope.filteredIdeas = $scope.ideasData.slice(begin, end);
});
// Data
$scope.ideasData = [];
for (var i = 0; i < 100; i++) {
$scope.ideasData.push('To do ' + i);
}
$scope.filteredIdeas = [];
$scope.currentPage = 1;
$scope.numPerPage = 10;
$scope.totalIdeas = $scope.ideasData.length;
分页本身设置正确,但以下是我在尝试单击下一页(或任何相关页面)时收到的错误:
Error: [$compile:nonassign] Expression 'undefined' used with directive 'pagination' is non-assignable!
如果我理解正确的话,这是不是表明我对双向绑定使用了不正确的东西?能够在这个Plunkr中复制错误:http://plnkr.co/edit/uyWQXPqjLiE4qmQLHkFy
有谁对我做错了什么有什么想法吗?
发布于 2016-02-11 14:45:06
举个具体的例子:
<uib-pager total-items="totalItems" items-per-page="4" ng-model="currentPage" ng-change="pageChanged()"></uib-pager>
然后将pageChanged绑定到您的作用域中:
$scope.pageChanged=function(){
console.log("Current page" + $scope.currentPage);
};
https://stackoverflow.com/questions/23419059
复制相似问题