ICodeNow ICodeNow - 1 year ago 65
AngularJS Question

Angular - pagination without user input

Apologies, the title is horrifically worded.


I have an angular app which I am using as a static display. There is no user interaction so most is based on timeouts. Page is loaded, after X amount of time based on X elements, the page reloads.


I want to show/hide only portions at at time. For example, one hundred results and I show 10, wait ten seconds, then show the next ten. Again, no user input though.

I am having trouble sorting the elements and hiding/displaying. From my understanding, I believe it is best to use a filter for this similar to pagination with buttons but then how do I trigger that automatically?

I use a JavaScript function to handle fade outs and window reset but I am lost.
I need something like..

<div ng-repeat="item in filtered = items | filter:search | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit"> -->


The limitTo and startFrom directives worked perfectly, in my controller I setup a $interval using the angular service and iterated "pages"..

startFrom:currentFlowerPage*flowerPageSize | limitTo: flowerPageSize

Answer Source

If you upgrade to AngularJS v1.4.0 or higher, you can use the limitTo filter to get the behavior you want.

<li class="visible" ng-repeat="x in items | limitTo:entryLimit:entryLimit*currentPage">

you can manipulate entryLimit and currentPage with$timeout as you please to play around with the page number and page size.

AngularJS v1.4.0 limitTo filter doc