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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
justaphaseAuthor Commented:
Thx for the info!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.