Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display two property combination in select option

Tags:

angularjs

Following is my select box

<select ng-model="colour" ng-options="c.id as c.name for c in colors" ng-init="colour=2">
    <option value="">--Select Colour--</option>
</select>

and following is code in controller

$scope.colors = [
    {id: 1, name: 'black', shade: 'dark'},
    {id: 2, name: 'white', shade: 'light'},
    {id: 3, name: 'red', shade: 'dark'},
    {id: 4, name: 'blue', shade: 'dark'},
    {id: 5, name: 'yellow', shade: 'light'}
];

In this select only name of the colour is displayed and my requirement is to show both name and shade in the option text. I have tried but no luck and did not found any useful post to do this.

Anybody have some idea to display both name and shade in the select option text (ed., black dark).

like image 753
MKB Avatar asked Mar 20 '23 17:03

MKB


2 Answers

You can append the shade to the name in the expression:

ng-options="c.id as (c.name + ' ' + c.shade) for c in colors"

Fiddle

like image 176
Gruff Bunny Avatar answered Mar 22 '23 07:03

Gruff Bunny


Hi have to update your ng-options expression For example:

c.id as c.name + ' ' + c.shade for c in colors
like image 40
Zhonk Avatar answered Mar 22 '23 07:03

Zhonk