Using multiple values in ng-options

8,119 views
Skip to first unread message

Brad McAlister

unread,
Mar 14, 2013, 4:01:44 PM3/14/13
to ang...@googlegroups.com
Is it possible to concatenate 2 values in a model array and push them back into the model?

I need to grab two values and put them together into a new one so I can use that to display them in the select box with ng-options.

It doesn't look like ng-options lets you pull two key values and to that. I tried something like this, "c.name and c.shade for c in colors", but that doesn't work. So I thought I could grab them and put them into the new item and from there so my model stay intact since I need to be able to access otehr parts of it on select change. Here's my best attempt to do that by pushing into the model but I can't push into it this way apparently. Plunker: http://plnkr.co/edit/1eNAFWmOrrQSMrWLkp7l?p=preview

What can I do to get two values displayed into each select option?

Thanks!

Clint Checketts

unread,
Mar 14, 2013, 4:08:33 PM3/14/13
to ang...@googlegroups.com
Would this suit your needs? http://plnkr.co/edit/TZG3Ra7yTWcAxcimz91B?p=preview

Concatenate the values in the expression?

<select ng-model="color" ng-options="(c.name+' '+c.shade) for c in colors"></select><br>


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Brad McAlister

unread,
Mar 14, 2013, 4:15:56 PM3/14/13
to ang...@googlegroups.com
Ah. Works perfectly. I have it in a cellTemplate for ngGrid so I have to escape the quotes but it works great and is super easy.

Thanks, Clint!

María Alejandra Gómez Casani

unread,
Apr 3, 2014, 11:34:35 AM4/3/14
to ang...@googlegroups.com
It help me a lot! Thanks :D

María Alejandra Gómez Casani

unread,
Apr 3, 2014, 11:34:44 AM4/3/14
to ang...@googlegroups.com

Sourav Kings

unread,
Oct 19, 2015, 4:08:09 AM10/19/15
to AngularJS, chec...@gmail.com
Thanks Brad for asking about issue at first place.

And thanks Clint; your solution worked like a charm.
Reply all
Reply to author
Forward
0 new messages