How to display custom label in SELECT dropdown using ng-options.

4,856 views
Skip to first unread message

Ashit Vora

unread,
Jul 15, 2013, 9:01:10 AM7/15/13
to ang...@googlegroups.com
Hi,

How can I display custom label in select dropdown.
I have two fields in my object that I was it in select dropdown.

result should be something like...

<select>
  <option value="1">object.name (object.city)</option>
  <option value="1">object.name (object.city)</option>
  <option value="1">object.name (object.city)</option>
  <option value="1">object.name (object.city)</option>
</select>

Emil Stolarsky

unread,
Jul 16, 2013, 9:39:17 AM7/16/13
to ang...@googlegroups.com
Hey Ashit,

You'd want to use the ng-options directive to achieve that. It works very similarly to ng-repeat. In your select element, you'd add the directive with the parameters "labelValue for optionValue in objArr" (Note, those are placeholders). Since you need the label to contain multiple properties and for it to be formatted a certain way, you could have 'labelValue' be a call to a function (with the arguments being the obj properties you want to show in the label) that returns a string the way you'd like to be formatted. 
Reply all
Reply to author
Forward
0 new messages