I am currently limiting my ng-repeat to 5 using a filter, but I'm wondering how I can paginate the data.
<div ng-repeat="job in jobs | limitTo:5">
I have a variable number of items that I am ng-repeating through, and I would like the user to be able to view these items in reasonable chunks -- five at a time, with next/previous buttons or page numbers to skip through. Is there an angular directive well-suited for this task? Would it be simpler to handle sending manageable chunks of data from the backend with a mongoose query?
How about
Angular
way of doingpagination
?You can just use the built in -
lightweight Angular/Bootstrap pagination
.In your
Javascript
file:In your view:
Yes, there's a nice directive for
AngularJS
calleddirPagination
. You can paginatetables
and almost everything that you need.Look at it on Github and if you want to see a demo, Plunker.
After you downloaded the
Javascript
and templateHtml
files, you need to do some basic steps:In your
Javascript
file, put:$scope.currentPage = 1;
// The page that should start the pagination.$scope.pageSize = 5;
// The limit of items per page.Change your div:
<div ng-repeat="job in jobs | limitTo:5">
to<div dir-paginate="job in jobs | filter:q | itemsPerPage: pageSize" current-page="currentPage"></div>
Add the pagination controls in your html file (Be sure to set the correct url for the template).
<dir-pagination-controls boundary-links="true" on-page-change="pageChangeHandler(newPageNumber)" template-url="dirPagination.tpl.html"></dir-pagination-controls>
UPDATE
I made a plnkr to demonstrate how it would look in your case. Please, take a look.