1

In angularJS I want to show negative number as red and positive as green.

I would like to apply a conditional CSS with ng-class. How do I check that number is negative?

<span ng-class="{true:'ok',false:'ko'}[number == ?what should I check?]">
    <b>Trend:</b>{{number}}
</span>

1 Answer 1

4

How about greater than or equal to 0 (for positive):

<span ng-class="{true:'ok',false:'ko'}[number >= 0]">
    <b>Trend:</b>{{number}}
</span>

The expression inside [ ] will be resolved to the boolean matching the previous statement in { }.

*Note: I'm assuming that the ok class is positive (green) and the ko class is negative (red). These css classes should be defined in your stylesheet.

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

Comments

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.