在AngularJS中为依赖下拉列表选择默认值
这个问题在这里已经有了答案:
如下所示分配selected1的值
$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"
}]
};
修改第二个下拉菜单中的ng选项
<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>
要在下拉菜单中听取更改,请使用ng-change
指令
<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>
注意: ng-options
被更改为包含整个对象
更新了Plunker
链接地址: http://www.djcxy.com/p/88079.html上一篇: Selecting a default value for dependant dropdowns in AngularJS