option value as string not index using ng:options

1,226 views
Skip to first unread message

007design

unread,
Feb 12, 2012, 1:35:44 PM2/12/12
to AngularJS
i'm really liking angular for handling my UI, taking care of binding,
etc. however, i'm having difficulty with the way it posts back to the
server. my server side code is set up using a library that takes care
of binding request parameters to java beans (stripes). unfortunately,
it doesn't work with JSON data in the body of the request.
so, what i'm doing is using angular to populate forms but then
submitting them using jQuery (and jQuery.serialize()). the trouble is
that select controls populated using ng:options have option elements
like this:
<option value="0">myValue</option>
rather than this:
<option value="myValue">myValue</option>

is there a way that I can have the value attribute of the option tags
be a value string rather than an index? i was hoping inputType would
help but that doesn't seem to work on select elements.

here's a fiddle demonstrating my issue:
http://jsfiddle.net/007design/tXgJx/

thanks very much!
007

Vojta Jina

unread,
Feb 12, 2012, 6:25:42 PM2/12/12
to ang...@googlegroups.com
I guess you want something like this: http://jsfiddle.net/vojtajina/2JWb2/

You can define your own transform fn, to convert the data into url-encoded format instead of json.
See Request / Response transformations in http://docs-next.angularjs.org/api/angular.module.ng.$http

V.

007design

unread,
Feb 12, 2012, 7:49:20 PM2/12/12
to AngularJS
Thanks for your response. Unfortunately, mixing angular and
urlencoded requests is turning out to be much more difficult. This
makes sense, of course, since it really seems designed for passing
data back in the request body, doing away with query params pretty
much altogether. I'm now working on using GSON to convert the JSON
requests into objects instead of binding the form field values / query
params to beans.
I hope I'm not posting too often. Nothing wrong with asking a lot of
questions, right?
Thanks again!
007


On Feb 12, 5:25 pm, Vojta Jina <vojta.j...@gmail.com> wrote:
> I guess you want something like this:http://jsfiddle.net/vojtajina/2JWb2/http://docs-next.angularjs.org/api/angular.widget.select
Reply all
Reply to author
Forward
0 new messages