To keep things simple, you can rebuild your model, as shown below, where the keys act as identifiers:
$scope.countries = { "c1" : { label : "Country 1", states:{ "s1":{ label:"State 1" }, "s2" : { label:"State 2" } } }, "c2" : { label:"Country 2", states:{ "s3":{ label:"State 3" }, "s4" : { label:"State 4" } } } };
HTML
<select ng-model="country" ng-options="countryId as countryDetails.label for (countryId, countryDetails) in countries"> </select> <select name="state" ng-model="state" ng-options="stateId as stateDetails.label for (stateId, stateDetails) in countries[country]['states']"> </select>
If in the duplicate temporary variables(countrySource)
you want to use the same models for other drop-down menus, choosing a country will change the settings for all the country
and state
drop-down lists on the page.
source share