0

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

2
  • 2
    try use ng-options . <select ng-model="diamond.category_id" ng-options="category as category for category in categoryData"> </select> Commented Jun 12, 2016 at 7:16
  • i figured it out thnk you @SSH answer is below Commented Jun 12, 2016 at 7:32

4 Answers 4

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

actually you give me vision
2

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>

Comments

0

you should do so:

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.