onkami
onkami

Reputation: 9411

Get text, not value from selected SELECT element with angular

I have defined my select element as (Jade syntax)

    select(ng-model="chosenProject.value" id="chosenProject"  ng-options="c.value as c.name for c in selectItems")

where selectItems is an array of objects with "value" and "name" fields.

I would like, if possible, to keep this notation as it is very compact. However, ng-model field ends up with only value of selected item. I however need both value and name of it. How do I proceed in order to obtain the text (aka "c.name" in code above) also?

Upvotes: 0

Views: 159

Answers (1)

thameera
thameera

Reputation: 9473

Remove the c.value as part. This will set the value of select to the whole c object.

select(ng-model="chosenProject" id="chosenProject"  ng-options="c.name for c in selectItems")

Now you chosenProject will be set to the whole JSON of the element selected, so you can get both the value and the name.

Upvotes: 1

Related Questions