0

I want to use ng-repeat but I need a specific starting position for pagination.

My code looks like this:

<div class="panel panel-default" ng-repeat="hotel in hotels | filter:search  | orderBy:sortBy.Name :order.reverse | limitTo:itemsPerPage">

I am using ng-repeat with limitTo(ex:5) directive. How can I set-up for ng-repeat an starting index?

Dayan
  • 7,634
  • 11
  • 49
  • 76
  • Hint: Create a new [`$filter`](https://docs.angularjs.org/guide/filter#creating-custom-filters) that will [`slice`](http://www.w3schools.com/jsref/jsref_slice_array.asp) the array in the given index. – Evandro Silva Mar 12 '15 at 14:50
  • possible duplicate of [Pagination on a list using ng-repeat](http://stackoverflow.com/questions/11581209/pagination-on-a-list-using-ng-repeat) – syymza Mar 12 '15 at 14:50
  • I have implemented the following filter in my app.js file: `app.filter('startFrom', function () { return function (input, start) { start = +start; return input.slice(start); } });` I receive the data in an asynchronous way and the filter is applied at page load. The problem is that the data is not available when the filter is used. How can I have filter applied after the data is available? – Emanuel Popescu Mar 12 '15 at 15:19

1 Answers1

0

I think the easiest way is to loop a subarray of the collection:

var arr = [1, 2, 3, 4, 5];
var subArray = arr.slice(1, 4);
print(subArray); // 2,3,4

Array.slice ref: http://www.w3schools.com/jsref/jsref_slice_array.asp

Eduardo Yáñez Parareda
  • 9,126
  • 4
  • 37
  • 50