Yousuf Jawwad
Yousuf Jawwad

Reputation: 3097

ng-repeat, how to call two items?

I am trying a select with ng-options. The problem is, my ng-options label is composed of two values ..

my code goes something like this

<select ng-model='item.batsman' ng-options='b.player.first_name b.player.last_name for b in shortlist'></select>

if i do, b.player.first_name .. the thing works fine, but i cannot have two values a label. what should i do?

i have tried a different method,

<td>
    <select ng-model='item.batsman'>
        <option ng-repeat='batsman in shortlist' value='{{ batsman.player.id }}'>
         {{ batsman.player.first_name }} {{batsman.player.last_name }}
        </option>
    </select>
</td>

but it doesn't let me pick a json value. my problem will be solved by picking up the json value, or by having the label as two values.

//mouse

Upvotes: 1

Views: 176

Answers (1)

joakimbl
joakimbl

Reputation: 18081

You can write the label expression as b.player.first_name + " " + b.player.last_name - like this:

<select ng-model='item.batsman' ng-options='b.player.first_name + " " + b.player.last_name for b in shortlist'></select>

Upvotes: 2

Related Questions