I looked through the previous questions on this topic but I could not find anything that looked like this.
My problem is that I want to make a second HTML radio button array depend on which radio button is selected first. Say the array of objects come to me like this:
"Names":[{
"name": "Fido",
"id": "1",
"type": [
{
"typeName": "Dog",
"typeId": "1"
},
{
"typeName": "Cat",
"typeId": "2"
},
{
"typeName": "Mouse",
"typeId": "3"
}
]
},
{
"name": "Bella",
"id": "2",
"type": [
{
"typeName": "Cat",
"typeId": "2"
},
{
"typeName": "Mouse",
"typeId": "3"
}
]
}]
My AngularJS code currently looks like this:
<label ng-repeat="item in nameList.Names">
<input type="radio" name="Name" ng-model="$parent.selectedName"
ng-value="item"> {{item.name}} </input>
<label ng-repeat="item in nameList.Names[$parent.selectedName.id].type"> <input
type="radio" name="Type" ng-model="$parent.selectedType"
ng-value="type"> {{item.typeName}}</input>
</label>
</label>
I'm quite sure this isn't working due to the $parent.selectedName.id part - ng-repeat already creates a child scope so this would be the "grandchild" of the original scope which means that $parent is just referring to the above script and not the rest of the code.
Is there a way to work around this so I can have a list that changes options based on the first selected value?
Edit: What I actually want to do is that I want to be able to select a radio button (in this case "Fido" or "Bella") and depending on selection have either array of "type" pop up in a second radio button list. Is there a way to make this work or do I need to split up the "Names"-object?