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>
Comments
Post a Comment