Skip to content

Commit

Permalink
fix(pagination): fix altering of current page caused by totals change
Browse files Browse the repository at this point in the history
  • Loading branch information
bekos committed Sep 28, 2013
1 parent aa3eaa9 commit eda6c80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/pagination/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ angular.module('ui.bootstrap.pagination', [])
}
};

$scope.$watch('page', function() {
self.render();
});

$scope.$watch('totalItems', function() {
$scope.totalPages = self.calculateTotalPages();
});
Expand All @@ -59,10 +63,6 @@ angular.module('ui.bootstrap.pagination', [])
self.render();
}
});

$scope.$watch('page', function() {
self.render();
});
}])

.constant('paginationConfig', {
Expand Down
8 changes: 8 additions & 0 deletions src/pagination/test/pagination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ describe('pagination directive', function () {
expect(getPaginationEl(-1).text()).toBe('Next');
});

it('does not change the current page when `total-items` changes but is valid', function() {
$rootScope.currentPage = 1;
$rootScope.total = 18; // 2 pages
$rootScope.$digest();

expect($rootScope.currentPage).toBe(1);
});

describe('`items-per-page`', function () {
beforeEach(inject(function() {
$rootScope.perpage = 5;
Expand Down

0 comments on commit eda6c80

Please sign in to comment.