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?
$first and $last It's common when using ng-repeat to add specific behavior to the first or last element of the loop, e.g. special styling around the edges. Instead, ng-repeat already supplies you with two ready boolean properties. $first is true for the first element, and $last is true for the last element.
NEST TWO ng-repeatThe first ng-repeat in the tr tag will create the rows and the second one in the td tag will create one column per element in the collection. By using one ng-repeat for the row and an other for the column, the rows and the columns of your table is now driven by a subset.
Note: The $index variable is used to get the Index of the Row created by ng-repeat directive. Each row of the HTML Table consists of a Button which has been assigned ng-click directive. The $index variable is passed as parameter to the GetRowIndex function.
However, some directives, such as ng-controller and ng-repeat, create new child scopes and attach the child scope to the corresponding DOM element.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With