I am trying to use a UI Bootstrap Pagination directive in my project, but for some strange reason the ng-model used for updating the current page is not working. The pagination is showing up correctly with the correct number of tabs and everything, but when I click on a different number, the ng-model variable is not getting updated. For the life of me, I can't figure out why not.
The code I am using is taken from the examples on the UI Bootstrap homepage:
<uib-pagination total-items="totalItems" ng-model="currentPage"
ng-change="pageChanged()"></uib-pagination>
The controller looks like this:
$scope.currentPage = 1;
$scope.totalItems = 160;
$scope.pageChanged = function() {
console.log('Page changed to: ' + $scope.currentPage);
};
Here are the different required sources I am including:
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://code.angularjs.org/1.4.8/angular.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.0.3.js"></script>
The strangest thing is I have created a plnkr which replicates my code and it works! You can see here: http://plnkr.co/edit/4DoKnRACbKjLnMH5vGB6
Can anybody think of any ideas that might be causing this not to work? I'm scratching my head here, and can't think of anything obvious I am doing wrong...
All help much apprecatiated!
I ran through the same problem and solved it by wrapping all Angular UI Bootstrap Pagination parameters into the object, like so:
$scope.pagination = {
currentPage: 1,
maxSize: 21,
totalItems: data.count
};
<uib-pagination
total-items="pagination.totalItems"
ng-model="pagination.currentPage"
max-size="pagination.maxSize"
boundary-link-numbers="true"
ng-change="pageChanged()"></uib-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