Angularjs, select combo with selected value in ng-repeat

Hello experts,

I have a ng-repeat and inside the repeat i have two comboboxes (select inputs) with the options based on an array each.
the value row.sourcefield is the selected value of the selects...
How do i do this?

The following code is what i have, but it doesn't work... surely ng-model can't have this "row.sourcefield"... but what to do?
<tr ng-repeat="row in fields">
    <td><select ng-model="row.sourcefield" ng-options="sfield.fieldname for sfield in sourcefields" data-placeholder="Choose an option..." class="select-search" tabindex="2"></select></td>
    <td><select ng-model="row.destinationfield" ng-options="dfield.fieldname for dfield in destinationfields" data-placeholder="Choose an option..." class="select-search" tabindex="2"></select></td>
    <td>Otto</td>
</tr>

Open in new window


Thx in advanced,
Miguel
LVL 1
justaphaseAsked:
Who is Participating?
 
ambienceCommented:
dfield.fieldname as dfield.title for dfield in destinationfields

Open in new window


simply means dfield.title will be used as the display label of option whereas dfield.fieldname will be * bound * to the model row.destinationfield.

For
dfield.fieldname for dfield in destinationfields

Open in new window


the model is the dfield and not dfield.fieldname.

I'm not sure what you mean by "is there a better way". You have to use the "select ... as ..." syntax of the comprehension expression to customize what is bound to the parent's (<select>) model.
0
 
justaphaseAuthor Commented:
I managed to do like this:

<tr ng-repeat="row in fields">
    <td><select ng-model="row.sourcefield" ng-options="sfield.fieldname as sfield.title for sfield in sourcefields" data-placeholder="Choose an option..." class="select-search" tabindex="2"></select></td>
    <td><select ng-model="row.destinationfield" ng-options="dfield.fieldname as dfield.title for dfield in destinationfields" data-placeholder="Choose an option..." class="select-search" tabindex="2"></select></td>
    <td>Otto</td>
</tr>

Open in new window

instead of doing like this: dfield.fieldname for dfield in destinationfields
I did like this: dfield.fieldname as dfield.title for dfield in destinationfields

Is there a better way?
0
 
justaphaseAuthor Commented:
Thx for the info!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.