角度:如果条件为真,如何更改单元格表的颜色 [英] Angular: How to change the color of cell table if condition is true
本文介绍了角度:如果条件为真,如何更改单元格表的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对象,该对象具有一个名为 changeColor
的变量.在我的html表中,如果 changeColor
为true,我想更改单元格颜色.我正在使用角度.
I have an object which has a variable called changeColor
. In my html table I want to change the cell color if changeColor
is true. I am using angular.
<tr ng-repeat="list in results">
<% if (!{{list.changeColor}} ) %>
<% { %>
<td bgcolor="red">{{list.value}}</td>
<% } %>
<td>{{list.price}}</td>
但是在测试之后,它始终为红色,并且<%if(!)%><%{%><%}%>
写在我的html页面中!你能帮我吗?
But after testing it is always red and the <% if (! ) %> <% { %> <% } %>
is written in my html page! Can you please help me?
对此进行了测试
<td style=".red {bgcolor: red;} .black {bgcolor: black;}"
ng-class='{red : list.changeColor, black: !list.changeColor}'>
{{list.price}}</td>
但这不起作用
推荐答案
您必须使用 ng-class
<tr ng-repeat="list in results">
<td ng-class='{red : list.changeColor, black: !list.changeColor}'>{{list.value}}</td>
<td>{{list.price}}</td>
</tr>
CSS
<style type="text/css">
.red {
color: red;
}
.black {
color: black;
}
</style>
这篇关于角度:如果条件为真,如何更改单元格表的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文