How do I assign default ngOptions
through parent/child models?
In this question OP shows a way form parent/child relationships using ngOptions
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" }
]
}
];
What you will see in this fork is that the dropdowns do not have any default values --- That is, the default option is "blank". In a normal use case this is a non issue, and default options are easily configurable through the controller which is explained well in the docs.
- How do I eliminate "blank" options for parent/child models using
ngOptions
? - How do I select default options either through the view or dynamically through the controller. It's important to remember here that the child default select options are first dependant on the parents selected option.