Is there a way to set default ngOptions through parent/child models?
Here, the OP demonstrates using ngOptions with parent/child relationships.
template
<select ng-model="x.site" ng-options="s.site for s in data"></select>
<select ng-model="x.name" ng-options="b.name for b in x.site.buildings"></select>
controller
$scope.x = {};
$scope.data = [
{
"site" : "Brands Hatch",
"buildings" : [
{ "name" : "Building #1" },
{ "name" : "Building #2" },
{ "name" : "Building #3" }
]
},{
"site" : "Silverstone",
"buildings" : [
{ "name" : "Building #4" },
{ "name" : "Building #5" },
{ "name" : "Building #6" }
]
}
];
In this fork, the dropdowns have default values as "blank". Typically, this is not an issue and defaults can be set easily through the controller as explained in the documentation.
- How can I remove the "blank" options for parent/child models using ngOptions?
- How do I select default options either from the view or dynamically from the controller? It's important to note that child default select options depend on the parent's selected option.