When I post a form with an Angular select, it sends the array index of the selected option, not its value. I need the string to be sent because the server doesn't know about these indices. How can I fix this?
From jsfiddle.net/2SuZG:
<form method="post" action="/my/post/endpoint">
<select name="resource" ng-options="r for r in ['a', 'b']"
ng-model="selectedResource"></select>
<button type="submit">Save</button>
</form>
You can see from the console output in the fiddle that the posted form is sending resource=0
, but I want resource='a'
. (Note: In my fiddle, I am serializing the form, but this is only to see what it would be posting. In my app I am actually posting to a real endpoint.)
This is similar to this question, but the answer there was "don't worry about the value". But in my case, I am posting a form so I am concerned with the value. I must be missing something very basic here. Thanks!
serialize
the form? You're using Angular... so your form should be represented very nicely in your$scope
if you've done things correctly. – Langdon May 26 '13 at 19:07