Tom O'Brien Tom O'Brien - 29 days ago 45
AngularJS Question

Angular UI Bootstrap Pagination ng-model not updating

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!

Answer

I ran throught the same problem and solved it by wraping all Angular UI Bootstrap Pagination paremeters into the object, like so:

JS

$scope.pagination = {
    currentPage: 1,
    maxSize: 21,
    totalItems = data.count;
};

HTML

<uib-pagination
    total-items="pagination.totalItems" 
    ng-model="pagination.currentPage" 
    max-size="pagination.maxSize"
    boundary-link-numbers="true" 
    ng-change="pageChanged()"></uib-pagination>