Selecting a default value for dependant dropdowns in AngularJS
This question already has an answer here:
Assign the value for selected1 as below
$scope.selectedd1= {
"category_name": "Automotive",
"category_id": "1",
"Subcategory": [{
"Name": "Two Wheeler",
"ID": "1"
}, {
"Name": "Four Wheeler",
"ID": "2"
}, {
"Name": "Heavy Moving Vehicles",
"ID": "3"
}, {
"Name": "Automobile Related",
"ID": "4"
}]
};
Modify the ng-options in the second dropdown
<select class="home_search_select" name="d2" id="d2"
ng-disabled="!selectedd1" ng-model="selectedd2"
ng-options="subcat.ID as subcat.Name for subcat in selectedd1.Subcategory track by subcat.ID">
<option class="home_search_select" value="">Select Sub Category</option>
</select>
To listen the changes in the dropdown use ng-change
directive
<select class="home_search_select" name="d1"
ng-model="selectedd1"
ng-change="homeChanged()"
ng-options="cat as cat.category_name for cat in categorydata track by cat.category_id" id="d1">
<option ng-value="">Select Category</option>
</select>
Note: ng-options
is changed to contain the entire object
Updated Plunker
链接地址: http://www.djcxy.com/p/88080.html