how will i change the color of a font based on a value using angularjs directives?

前端 未结 1 1848
小鲜肉
小鲜肉 2021-01-06 00:33

I would like to create a directive that can change the font color of the text displayed on a span based on some value that is not displayed.
I have an array:

相关标签:
1条回答
  • 2021-01-06 01:24

    You can use ng-class

    <span ng-class="{red: past == 'yes', black: past == 'no'}">{{somedue.date}}</span>
    

    where the classes red or black will be applied. You can style those via CSS to make the color red / black.

    Example: http://jsfiddle.net/TheSharpieOne/NHS73/

    Your data structure was odd in your example, it has been modified in mine to showcase ng-class.

    Also: You could use true / false and not need to do a string comparison to 'yes'/'no'.

    0 讨论(0)
提交回复
热议问题