2016-06-12 10 views
0

ng-selected funktioniert nicht mit ng-repeat, im inspect-Element kann ich ng-selected = true sehen und es gibt ein Attribut für die Option element.my code ist wie folgt und wird ausgegeben Screenshot ist auch unten angegeben.ng-selected arbeitet nicht mit ng-repeat angularjs

<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

+2

Ausprobieren Verwenden 'ng-options'. '' –

+0

ich fand heraus thnk sie @SSH antwort ist unter –

Antwort

2

ich es herausgefunden durch Verwendung ng-Optionen

<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> 
0

Sie sollten dies tun:

<option ng-selected="diamond.category_id == category.id" 
          value="{{category.id}}" 
          ng-repeat="category in categoryData" 
       >{{category.id}}</option> 
+0

immer noch dasselbe ergebnis –

2

Ihr Code wie folgt sein sollte:

<select class="form-control" ng-options="item.id for item in categoryData track by item" 
ng-model="diamond.category_id"> 
</select> 
+0

danke @Vino Dang –

+0

Hilft es dir? –

+0

eigentlich gibst du mir eine Vision –

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]">