I am using AngularJS for my web app. My objective is to have two dropdowns list using ng-options.
- The first dropdown showing the country list
- The other gives the language preferences for the selected country
Being still new to AngularJS, I am able to display the data but the entire object is displayed as a single option, I am unable to split each data.
Kindly find the code below that I used.
HTML
<select ng-model="selectedRegion" ng-options="region.countryName for region in eyebrow.regionSelector"></select>
<select ng-model="selectedRegion.selectLang" ng-options= "selectedRegion.selectLang for region in selectedRegion track by selectedRegion.countryName"></select>
JS:
angular.module ('appngOption')
.controller ('headerController', function($scope) {
$scope.eyebrow = { regionSelector: [
{
"id": 1,
"countryName": "Belgium",
"selectLang": ["Dutch", "English", "French"]
},{
"id": 2,
"countryName": "France",
"selectLang": ["English", "French"]
}]}
});
Example: Dutch, English and French should be each separate dropdown option when Belgium is selected. & English and French should be each separate dropdown option when France is selected.
Kindly review the code and let me know if i had missed anything. Your help is deeply appreciated.