0

I'm looping through array of events and show it on front. There is directive "score" inside div, and I want to inject number of array element in the directive code using $index. Works fine until I tried to add orderBy to ng-repeat. And now $index works based on ordered list. Any suggestion how to inject number of current element of array?

data:

"events" : [{
"event_score" : [0,1]
},
{
"event_score" : [0,1]
},
...
]

This is my code:

<div ng-repeat="e in events | orderBy:'match_time'">
  <score index="{{$index}}" user="{{screen_name}}"></score>
</div>
simeg
  • 1,889
  • 2
  • 26
  • 34
n00b43677
  • 187
  • 2
  • 16

1 Answers1

0

Have you tryed assign events to a $scope variable?

  $scope.events = [{
    "event_score" : [0,1]
    },
    {
    "event_score" : [0,1]
    },
    ...
    ];

<div ng-repeat="e in events">
  Current item is {{$index}}
  <score index="{{$index}}" user="{{screen_name}}"></score>
</div>

which is pretty well how angularjs works :P

Then

orderBy:'match_time' will not work cause you don't have a key called match_time in your array( as i can see), so it will work if you have something like

 $scope.events = [{
        "event_score" : [0,1],
        "match_time": 5600
        },
        {
        "event_score" : [0,1],
        "match_time":4500
        }
        ];
simeg
  • 1,889
  • 2
  • 26
  • 34
itsme
  • 48,972
  • 96
  • 224
  • 345