I'm using a fairly simple implementation of Angular Bootstrap UI's pagination directive, yet I keep getting an error I cannot figure out. Here's the relevant snippets:
<ul>
<li ng-repeat="todo in filteredIdeas">
{{todo}}
</li>
</ul>
<pagination ng-model="currentPage" total-items="totalIdeas"></pagination>
Here are the relevant portions of my $scope in the controller:
// 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;
The pagination sets itself up correctly, but here's the error I receive when trying to click on the next page (or any page for that matter):
Error: [$compile:nonassign] Expression 'undefined' used with directive 'pagination' is non-assignable!
If I understand correctly, this is indicating that I'm using something improperly for two-way binding? Was able to replicate the bug in this Plunkr: http://plnkr.co/edit/uyWQXPqjLiE4qmQLHkFy
Anyone have any thoughts on what I'm doing wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…