我将如何改变字体的基于使用angularjs指令值的颜色? [英] how will i change the color of a font based on a value using angularjs directives?
问题描述
我想创建一个指令,可以改变的基础上没有显示某个值的跨度中显示的文本的字体颜色
我有一个数组:
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:
$scope.due =[{somedate: "April.8.2010"}, {past:"yes"}];
如果的过去的价值是肯定的,那么跨度内的值:<跨度> {{somedue.date}}< / SPAN>
将是红色,否则,如果过去是否定的,那么字体颜色为黑色。我是新与angularjs所以我将AP preciate,如果你能在我这怎么能使用angularjs做提示。
If the value of "past " is yes, then the value inside the span: <span>{{somedue.date}}</span>
will be color red, else if "past" is no, then font color is black. I am new with angularjs so i would appreciate it if you can suggest on how can i do this using angularjs.
推荐答案
您可以使用纳克级
<span ng-class="{red: past == 'yes', black: past == 'no'}">{{somedue.date}}</span>
,其中红色或黑色的类将被应用。您可以通过风格的CSS,使红色/黑色。
where the classes red or black will be applied. You can style those via CSS to make the color red / black.
例如: 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'
.
这篇关于我将如何改变字体的基于使用angularjs指令值的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!