I have edited the question as it became too long Hi I have this angular code :
var mod = angular
.module("myMod",[])
.controller("myCont",function($scope){
var obj = [
{name : "Monica", others :[{age:20},{salary:20000}]},
{name : "Rachel", others :[{age:16},{salary:28000}]},
{name : "Pheobe", others :[{age:24},{salary:30000}]}
]
$scope.obj1 = obj;
})
and this html file :
<!DOCTYPE HTML>
<html >
<head>
<script src = "angular.js"></script>
<script src = "angularmy.js"></script>
</head>
<body ng-app="myMod" ng-controller="myCont">
<div>
<ol>
<li ng-repeat="item in obj1" ng-init="parentIndex=$index">{{item.name}}
<ol ng-repeat="items in item.others">
<li >{{items.age }} parentIndex - {{parentIndex}} index - {{$index}}</li>
<li >{{items.salary }} parentIndex - {{parentIndex}} index - {{$index}}</li>
</ol>
</li>
</ol>
</div>
</body>
</html>
But it is giving the index of the second nested list item also 0 :
Monica
- 20 parentIndex - 0 index - 0
- parentIndex - 0 index - 0
- parentIndex - 0 index - 1
- 20000 parentIndex - 0 index - 1
Rachel
- 16 parentIndex - 1 index - 0
- parentIndex - 1 index - 0
- parentIndex - 1 index - 1
- 28000 parentIndex - 1 index - 1
Pheobe
- 24 parentIndex - 2 index - 0
- parentIndex - 2 index - 0
- parentIndex - 2 index - 1
- 30000 parentIndex - 2 index - 1
Could someone please let me know what is wrong in this code ? Why four outputs are coming instead of 2 ???