I have an array like this in my controller:
$scope.myArray = [
{
id: 1,
name: "my object",
options: [
{
id: 1,
key: "key1",
value: "value1"
},
{
id: 2,
key: "key2",
value: "value2"
}
]
},
{
id: 2,
name: "my object 2",
options: [
{
id: 1,
key: "key3",
value: "value3"
},
{
id: 2,
key: "key4",
value: "value4"
}
]
}
]
I want to loop through this in my template in angular. This is what I have so far:
<div ng-repeat="obj in myArray">
<input ng-model="myArray[$index].name" />
<div ng-repeat="option in obj.options">
/*How can I use $index again here to loop through the options array ? Wouldn't $index be for the parent loop */
<input ng-model="obj.options[$index].value" />
</div>
</div>
My question is that in the above inner loop where I am trying to use obj.options[$index]
, will this refer to the correct index of the options array or will it still think that it is using the index of the parent array ?