1

Here is the problem, I create table with ng-repeat, in table td I have select with option, I need to set selected option.

 <tr id="edit" ng-repeat="x in products">
     <td style="width: 2%;display: none;">{{x.id}}</td>
     <td style="width: 16%"><h6 style="font-weight: normal;" ng-bind="nameResult"  ng-hide="false"></h6>
       <select style="margin: -16px 0 0 0;" class="span12" style="margin: 0;" ng-change="loadProductData(x)" id="product_list" ng-options="prod.product_name as prod.product_name for prod in items track by prod.product_id" ng-model="selectedOption">    
           <option value="">Select product</option>
           <option label="Registracija korisni" value="57">Registracija korisni</option>
           <option selected="selected" label="Testing of platform" value="58">Testing of platform</option>
           <option label="Test 2" value="63">Test 2</option>
           <option label="irfam" value="87">irfam</option>
           <option label="ddd" value="88">ddd</option>
      </select>
     </td>
 <tr> 

So I have multiple select with same ng-model how to set selected different option for each select.

Vidya Sagar
  • 1,699
  • 3
  • 17
  • 28
Earphan
  • 364
  • 1
  • 4
  • 13

1 Answers1

1

Since your ng-model="selectedOption" then angular will select the option which matches selectedOption. Since you are tracking by prod.product_id then selectedOption will need to be set to a prod.product_id.

I see you have set some options manually. If these are not being selected properly you may need to add these items to your prod object, then let angular create the options for you.

Miles P
  • 710
  • 4
  • 12
  • this is just for preview, course I create option in repeat, can you explain me whats mean "Since you are tracking by prod.product_id then selectedOption will need to be set to a prod.product_id." – Earphan Aug 05 '15 at 12:45
  • Can you send me some code? How to set prefered value selected for each select – Earphan Aug 05 '15 at 12:46
  • There are a lot of examples at https://docs.angularjs.org/api/ng/directive/ngOptions – Miles P Aug 05 '15 at 13:01
  • selectedOption is your model data. Angularjs will select the option defined in the track by expression. In this case track by is prod.product_id. Therefore angular will select the option who's value matches selectedOption. – Miles P Aug 05 '15 at 13:04
  • thank you man you solve my problem. Miles P – Earphan Aug 05 '15 at 13:15