0

I want to add different CSS to every option of ui-select as given in the image so that every option is shown in different text-color

enter image description here

Here is the Plunk with the code: Plunk

I also tried with giving different li as shown here

<ui-select-choices repeat="item in (itemArray) track by item.id">
   <li style="color:green;">Pending</li>
   <li style="color:red;">Rejected</li>
   <li style="color:blue;">Approved</li>
</ui-select-choices>

but when I select the item the css won't persist.

1 Answer 1

3

You could have associated color for each item in the array. Like this:

$scope.itemArray = [
    {id: 1, name: 'Pending', color: 'green'},
    {id: 2, name: 'Rejected', color: 'red'},
    {id: 3, name: 'Approved', color: 'blue'},
];

And, then in the ui-select,

<ui-select-match>
    <span style="color: {{$select.selected.color}}" ng-bind="$select.selected.name | limitTo: 20"></span>
</ui-select-match>

<ui-select-choices repeat="item in (itemArray) track by item.id">
    <span style="color: {{item.color}}" ng-bind="item.name"></span>
</ui-select-choices>

working plunker

Sign up to request clarification or add additional context in comments.

6 Comments

The selected item still does not have color.
@maenolis thanks for noticing, I have updated (had forgotten to save)
@AayushiJain no prob, glad it could help a bit!
@Taysumi oh! Not sure what could go wrong on IE 11. Can you Ctrl+F5 plunker or open in private/incognito mode?
@tanmay Oh well. I don't really care to be honest. I tried it on my mobile with chrome, works like a charm. I use IE only because I have to (company). Nice solution. +1
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.