0

JSBIN example

I'm using an object for my ng-options :

$scope.data = {
    option1 : 1,
    option2 : 1,
    option3 : 1,
    option4 : 2 
  };

Notice that options 1-3 has the same value 1

Using this select element with the ng-options directive

<select   ng-model=combo_value 
          ng-change='set_value()'
          ng-options="k for (k,v) in data">
</select>

I'm unable to select options 1 and 2.

Even weirder is that using the keyboard i can select options 1 & 2 but when selecting with the mouse, the select is automatically jumping to option 3 (guessing that it's because it's the last option with the value 1).

I tried different ng-options expression but none seem to work

v as k for (k,v) in data
k for (k,v) in data track by $index
k for (k,v) in data track by k

note : k is always unique

2 Answers 2

0
k as v for (k, v) in data

should let you select any option. In this case your model combo_value will get the value option1, option2, etc.

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

Comments

0

Use ng-options="k as k for (k,v) in data" to show and get option1, option2, option3, option4 as selected value.

Here the working example:

http://plnkr.co/edit/S8RBm8?p=preview

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.