user3840211 user3840211 - 10 months ago 34
AngularJS Question

How to get the next item in ng-repeat for an object?

I have an object as follows:

scope.items = {
"poor-John-1": {
"_id": "poor-John-1",
"name": "poor-John-1",
"sName": "room-poor-John-2"
"poor-John-2": {
"_id": "poor-John-2",
"name": "poor-John-2",
"sName": "room-poor-John-2"


I have rendered the object in the following way

<tr ng-repeat="item in items | orderObjectBy: '_id' track by item._id" ng-class="getStyle(item, next_item)"><td>{{item.sName}}</td></tr>

What I want to do is, pass, the current and next_item to the getStyle function, since its not an array, $index is not pointing the value. I have data in object.


Maybe you can do this with

$scope.keys = Object.keys($scope.items) // put keys on scope

// get next from keys
<tr ng-repeat="(key, item) in items track by item._id"  ng-class="getStyle(item, items[keys[$index +1]])">
  <td>next : {{items[keys[$index +1]]}}</td>

Look this, tell me if it's what you want