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>
But after testing it is always red and the <% if (! ) %> <% { %> <% } %>
is written in my html page! Can you please help me?
Tested this
<td style=".red {bgcolor: red;} .black {bgcolor: black;}"
ng-class='{red : list.changeColor, black: !list.changeColor}'>
{{list.price}}</td>
But it does not work
In HTML, table background color is defined using Cascading Style Sheets (CSS). Specifically, you use the background-color property to define background color. You can apply this property against the whole table, a row, or a single cell.
Cell background colors are set by applying the bgcolor attribute to a <tr> tag (to color the row) or to a <td> tag (to color the cell). Cell colors override row colors which, in turn, override table background colors.
The HTML <td> bgcolor attribute is used to specify the background color of a table cell.
The HTML <table> bgcolor Attribute is use to specify the background color of a table. Attribute Values: color_name: It sets the text color by using the color name.
You have to use 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With