Reputation: 442
I am using : https://github.com/michaelbromley/angularUtils/tree/master/src/directives/pagination
I want after adding a new element to the list, to make my currentPage be the last page. I tried using the paginationService like this:
paginationService.setCurrentPage('ID', Math.ceil(paginationService.getCollectionLength("ID")/ITEMSPERPAGE));
However, the problem is that the collection is updated after a few miliseconds, which means that the 'getCollectionLength' function will not return the correctValue.
Upvotes: 1
Views: 374
Reputation: 442
I decided to try and use the $timeout module from angular, since it made sense dir-paginate would use the same clicks angular uses to update. It works just as expected, code is now:
$timeout(function() {
paginationService.setCurrentPage('ID', Math.ceil(paginationService.getCollectionLength("ID")/ITEMSPERPAGE));
});
Just make sure you have $timeout in the modules import AND in the function params for the ng-controller. Silly mistake, but I forgot to do it.
Upvotes: 2