6

I have this code:

<select ng-options="key as value for (key, value) in {{set.values}}" ng-init="set.value" ng-model="item.styles[group][name].value"></select>

I need to set a style to the options like this (generated):

<option style="background: green;">
<option style="background: red;">

How? Is it possible? Or do I need a directive or some other fancy code?

2
  • do you want generate them depends on a condition? Commented Mar 24, 2014 at 7:22
  • I have them in an object. Commented Mar 24, 2014 at 7:42

1 Answer 1

-1

You can apply conditional styles via Angular's built-in ng-style directive

Markup

<span ng-style="myStyle">Sample Text</span>

Logic

$scope.myStyle = {
   background: '#000000'
};

Where the directive takes any valid expression

See also:

How do I conditionally apply CSS styles in AngularJS?

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

2 Comments

I don't have an element to attach it on because I use "ng-options" to create option element.

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.