0

I have a select where I select fields by name (email, name, account, etc), when I click on a field in an other select I have to show the database values for this field. I get then like this: [{"name":"name1"},{"name":"name2"}] or [{"email":"email1"},{"email":"email2"}] so I can't use a value.name or a value.email in ngOptions (but I have the name of the field in a scope var it helps)

I have tried with all options in ngOptions documentation for arrays and for object, one of the I retrieve the first element, other one a list of [object Object].

I wan't to make a select where the value and the label are the same, like:

<option value="name1">name1</option>
<option value="name2">name2</option>
2
  • ` I can't use a value.name or a value.email in ngOptions` why? Commented Aug 19, 2015 at 9:55
  • Because the field selected is dynamic he gets name OR email OR ... Commented Aug 19, 2015 at 9:59

1 Answer 1

1

You could use something like this:

<select ng-model="selected"
      ng-options="name[utils.keys(name)[0]] for name in names">
</select>

jsFiddle: http://jsfiddle.net/ma2939ab/1/

Sign up to request clarification or add additional context in comments.

1 Comment

That works, but if some one want to use it look in the jsFiddle where the utils.keys are defined ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.