How can I apply style on some item in a list that satisfy listed condition:
<div data-ng-repeat="item in items">
<div data-ng-style="{'background' : 'red' : item.selected}> {{item.name}}
<div>
<div>
How is it possible to apply this style on item that is selected.
Explanation: {CssProperty: Condition ? if condition is True : If condition is False}
CssProperty : meaning background, color, font-size etc..
Condition: just like a If statment..
after the : define the property value for the true and false Condition .for the the CssProperty.
here we have no value if condition is false.
any true or false value should be the Proper value for the CSSProperty. So for background it's #ffffff or White.
Try this code,
Ironically I just looked this up, the correct thing is to obviously use classes as they have this designed within them.
However, you can do conditionals thanks to the JavaScript ability to return the last value with &&
You can use this method described further here. (example below)
I think it would be best to use
ng-class
for your problem. You then make a new class for the red background, eg:And then use this class according to the condition:
(don't forget the single quotes around the class name, they are easily overlooked)
Please refer below