ng-selected不使用ng-repeat,在inspect元素中我可以看到ng-selected = true并且选项元素上有选定的属性。我的代码如下,输出截图也在下面给出。
<div class="row">
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<label for="">{{diamond.category_id}}</label>
</div>
<div class="col-xs-10 col-sm-10 col-md-10 col-lg-10">
<select ng-model="diamond.category_id" class="form-control">
<option ng-selected="{{diamond.category_id == category.id}}"
value="{{category.id}}"
ng-repeat="category in categoryData"
>{{category.id}}</option>
</select>
</div>
答案 0 :(得分:2)
您的代码应该是这样的:
<select class="form-control" ng-options="item.id for item in categoryData track by item"
ng-model="diamond.category_id">
</select>
答案 1 :(得分:2)
我通过使用ng-options
来解决这个问题<div class="row">
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<label for="">{{diamond.category_id}}</label>
</div>
<div class="col-xs-10 col-sm-10 col-md-10 col-lg-10">
<select ng-model="diamond.category_id"
ng-options="category.id as category.fullName for category in categoryData"
class="form-control">
</select>
</div>
</div>
答案 2 :(得分:0)
你应该这样做:
<option ng-selected="diamond.category_id == category.id"
value="{{category.id}}"
ng-repeat="category in categoryData"
>{{category.id}}</option>
答案 3 :(得分:0)
<select class="form-control"
name="country"
ng-model="address.country"
ng-options="country as country.name for country in countries"
ng-change="address.province = address.country.data; address.province = address.country.data[0];address.city = address.province.data[0]">