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?
The ability to use ng-model
was introduced in ui-bootstrap-tpls-0.11.0.js
, as explained in the changelog:
Both
pagination
andpager
are now integrated withngModelController
.
*page
is replaced withng-model
*on-select-page
is removed sinceng-change
can now be used
Before:<pagination page="current" on-select-page="changed(page)" ...></pagination>
After:<pagination ng-model="current" ng-change="changed()" ...></pagination>
Since you are using ui-bootstrap-tpls-0.10.0.min.js
, you need to use the old syntax - with page
instead of ng-model
:
<pagination page="currentPage" total-items="totalIdeas"></pagination>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With