How Do I Get The $index Of Element In An Ng-repeat When Repeating Over An Object?
I know object values don't have indexes but say I have an object named foo with 5 keys and I do:
I will end up with 5 divs on my page. M
Solution 1:
You could still use {{$index}}
when repeating non array objects.
Markup:
<divng-app><divng-controller="testCtrl"><divng-repeat="(key, value) in data"><span>{{$index}} -</span><span>{{key}} -</span><span>{{value}}</span></div></div></div>
Controller
functiontestCtrl($scope) {
$scope.data = {
prop1: 'a',
prop2: 'b',
prop3: 'c',
prop4: 'c'
}
}
Output:
0 - prop1 - a1 - prop2 - b2 - prop3 - c
3 - prop4 - c
See this fiddle for your reference
Post a Comment for "How Do I Get The $index Of Element In An Ng-repeat When Repeating Over An Object?"