0

I am facing an issue with ng-model in angularjS. I have this piece of code :

<select ng-model="node[col.field]">
    <option selected="selected">-</option>
    <option>I</option>
    <option>W</option>
    <option>E</option>
</select>

For example, When the user selects "I", I'd like to have node[col.field] = "1" and not node[col.field] = "I". Is that possible to do that ?

1
  • set value=1 in <option> tag Commented Mar 13, 2016 at 10:23

1 Answer 1

1

Have you tried using the value attribute of option. I feel you can declare what really every option should mean and then you might be able of using your method.

http://www.w3schools.com/tags/att_option_value.asp

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

3 Comments

Thanks it works, i didn't think about it. Just one question to be sure that I understood. When you put "value" one the option tag, ng-model value is binded with this value and not with what the displayed value ?
Yes that is right! But it is not an angular specific solution, adding the value attribute works for any JavaScript need since the Dom element will use the value attribute first before the displayed value
Great ! I got it, Thanks for your answers.

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.