Iladarsda
Iladarsda

Reputation: 10694

AngularJS - select text with concatenated text

Can you please advice me, how to get a select looking like this:

<select ng-model="model.user" ng-options="user._id as user.title for user in users">
    <option value="43f01">John Doe - Administrator</option>
    <option value="43f02">Adam Smith - Superviser</option>
</select>

from this data:

[
    { "name" : "John Doe", "title" : "Administrator", "_id":"43f01"},
    { "name" : "Adam Smith", "title" : "Superviser", "_id":"43f02"},
]

Any suggestions much appreciated.

Upvotes: 0

Views: 60

Answers (1)

Lucius
Lucius

Reputation: 2872

ng-options accepts an angular expression for option text, you can just create string there

<select ng-model="model.user" ng-options="user._id as (user.name + ' - ' + user.title) for user in users">

Upvotes: 2

Related Questions