I have a dataset that includes region, states and cities. I have 3 select lists which contain the values of each of those data types. I would like the states and cities select lists to populate with the data from their parent object only when it's selected.
Code:
https://jsfiddle.net/tedleeatlanta/4egcw5zs/18/
function TheController($scope) {
$scope.locations = [
{
"Region": "USA",
"States": [
{
"stateName": "Georgia",
"Cities": [
{
"cityName": "Dunwoody"
}
]
},
{
"stateName": "Florida",
"Cities": [
{
"cityName": "Clearwater"
}
]
}
]
},
{
"Region": "Canada",
"States": [
{
"stateName": "Quebec",
"Cities": [
{
"cityName": "SomeplaceElse"
}
]
}
]
},
{
"Region": "Europe",
"States": [
{
"stateName": "England",
"Cities": [
{
"cityName": "London"
}
]
},
{
"stateName": "France",
"Cities": [
{
"cityName": "Paris"
}
]
},
{
"stateName": "Germany",
"Cities": [
{
"cityName": "Munich"
}
]
},
{
"stateName": "Spain",
"Cities": [
{
"cityName": "Portugal"
}
]
}
]
}
];
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller="TheController" ng-app>
Region:
<select ng-model="regionSelect" ng-options="location.Region as location.Region for location in locations"><option value="">Select Region</option>
</select>
<br/>
State:
<select ng-disabled="!regionSelect" ng-model="stateSelect" ng-options="location.Region.States.stateName as location.Region.States.stateName for location in locations"><option value="">Select State</option>
</select>
<br/>
Cities:
<select ng-disabled="!stateSelect" ng-model="citySelect" ng-options="location.{{regionSelect}}.{{stateSelect}}.stateName as location.Region.States.stateName for location in locations"><option value="">Select City</option>
</select>
<hr/>
Location: {{locationId}} <br/>
Another Location: {{anotherLocationId}}
</div>
I can't seem to get the ng-options verbiage correct to parse the states and cities from my dataset when the parent item is selected.