Angular: How to change the color of cell table if condition is true

后端 未结 3 1881
情深已故
情深已故 2021-02-14 10:35

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.<

相关标签:
3条回答
  • 2021-02-14 11:00

    Don't put so much logic in your views. Try this instead:

    ngClass directive

    It will allow you to change the td class based on an expression.

    0 讨论(0)
  • 2021-02-14 11:06

    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>
    
    0 讨论(0)
  • 2021-02-14 11:06
     <td ng-class="{'negative':daily.MTDCompSales<0,'positive':daily.MTDCompSales>0}">{{daily.MTDCompSales | number:0}}</td>
    

    This line of code changes based on data value, if data is positive or negative

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