How to access previous and next item in angularjs ng-repeat
angularjs, angularjs-ng-repeat
Solution
You can save the results of the filter into a new variable:
event in filteredEvents = (events | myMinDate: 'start':config.now | orderBy: 'start')
Then:
filteredEvents[$index - 1]
Problem
I have a list of events that I display using ng-repeat. From each event, I need to access the previous and next event for HTML display reasons. When I don't use filters, this works well using ``` events[$index - 1] ``` However, if I filter and re-order the events using ``` event in events | myMinDate: 'start':config.now | orderBy: 'start' ``` I cannot use this techique, as the events array still refers to the original (unfiltered, unsorted) data structure. It's unfortunate there is no data array of the filtered data or something like $previous and $next. Any ideas how this can be achieved without touching the actual events array?