Reputation: 49
ng-selected not working with ng-repeat,in inspect element i can see ng-selected= true and there is selected attribute on option element.my code is as follows and output screenshot is also given below.
<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>
Output Link : http://prntscr.com/bfcdwa
Upvotes: 0
Views: 291
Reputation: 1
<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]">
Upvotes: 0
Reputation: 49
I figured it out by using 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>
Upvotes: 2
Reputation: 2370
Your code should be like this:
<select class="form-control" ng-options="item.id for item in categoryData track by item"
ng-model="diamond.category_id">
</select>
Upvotes: 2
Reputation: 1
you should do so:
<option ng-selected="diamond.category_id == category.id"
value="{{category.id}}"
ng-repeat="category in categoryData"
>{{category.id}}</option>
Upvotes: 0