javascript - Getting actual array index from ng-repeat -


let's have following array

$scope.stuff = [     {name: "one", order: 1},     {name: "three", order: 3},     {name: "two", order: 2} ] 

then list using ng-repeat so:

<div ng-repeat="(key, data) in stuff | orderby:'-order'">     {{ data.name }} - {{ key }} - {{ $index }}     <br /> </div> 

it display:

1 - 0 - 0 2 - 1 - 1 3 - 2 - 2 

i'd able know in actual array, these items coming in $scope.stuff

so i'd know 3 in array index 1 in $scope.stuff , not array index 2 in sorted ng-repeat.

i'm new angular have suggestions?

i dont think ng-repeat has functionality, used array indexof method actual index.

 <div ng-repeat="(key, data) in stuff | orderby:'-order'">     {{ data.name }} - {{ key }} - {{ $index }} - {{stuff.indexof(data)}}     <br /> </div> 

http://plnkr.co/edit/xjtz6y3xfqs6bs3lgjk6


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -