Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/directives/pagination/dirPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,19 @@

function goToPage(num) {
if (paginationService.isRegistered(paginationId) && isValidPageNumber(num)) {
var oldPageNumber = scope.pagination.current;

scope.pages = generatePagesArray(num, paginationService.getCollectionLength(paginationId), paginationService.getItemsPerPage(paginationId), paginationRange);
scope.pagination.current = num;
updateRangeValues();

// if a callback has been set, then call it with the page number as an argument
// if a callback has been set, then call it with the page number as the first argument
// and the previous page number as a second argument
if (scope.onPageChange) {
scope.onPageChange({ newPageNumber : num });
scope.onPageChange({
newPageNumber : num,
oldPageNumber : oldPageNumber
});
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/directives/pagination/dirPagination.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,15 @@ describe('dirPagination directive', function() {
$scope.$apply();
expect($scope.myCallback).toHaveBeenCalledWith(2);
});

it('should pass the previous page number to the callback', function() {
compileWithAttributes(' on-page-change="myCallback(oldPageNumber)" ');
var pagination = containingElement.find('ul.pagination');

pagination.children().eq(3).find('a').triggerHandler('click');
$scope.$apply();
expect($scope.myCallback).toHaveBeenCalledWith(1);
});
});

describe('total-items attribute', function() {
Expand Down