Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 81164da

Browse files
bekospkozlowski-opensource
authored andcommitted
fix(pagination): fix altering of current page caused by totals change
Closes #1079
1 parent 58cd74b commit 81164da

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/pagination/pagination.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ angular.module('ui.bootstrap.pagination', [])
4646
}
4747
};
4848

49+
$scope.$watch('page', function() {
50+
self.render();
51+
});
52+
4953
$scope.$watch('totalItems', function() {
5054
$scope.totalPages = self.calculateTotalPages();
5155
});
@@ -59,10 +63,6 @@ angular.module('ui.bootstrap.pagination', [])
5963
self.render();
6064
}
6165
});
62-
63-
$scope.$watch('page', function() {
64-
self.render();
65-
});
6666
}])
6767

6868
.constant('paginationConfig', {

src/pagination/test/pagination.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ describe('pagination directive', function () {
9595
expect(getPaginationEl(-1).text()).toBe('Next');
9696
});
9797

98+
it('does not change the current page when `total-items` changes but is valid', function() {
99+
$rootScope.currentPage = 1;
100+
$rootScope.total = 18; // 2 pages
101+
$rootScope.$digest();
102+
103+
expect($rootScope.currentPage).toBe(1);
104+
});
105+
98106
describe('`items-per-page`', function () {
99107
beforeEach(inject(function() {
100108
$rootScope.perpage = 5;

0 commit comments

Comments
 (0)