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

Commit

Permalink
fix(pagination): fix altering of current page caused by totals change
Browse files Browse the repository at this point in the history
Closes #1079
  • Loading branch information
bekos authored and pkozlowski-opensource committed Sep 29, 2013
1 parent 58cd74b commit 81164da
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 81164da

Please sign in to comment.