使用子元素中的ng-if指令更改父元素的样式

时间:2017-07-07 21:55:21

标签: javascript angularjs angular-ng-if

我是棱角分明的新手。根据条件,我改变细胞的背景。但如果我能改变整条线的背景,我将不仅仅是高兴 以下是代码示例:

<table>
    <thead>
        <tr>
            <td>
                Status
            </td>
            <td>
                Time waiting
            </td>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="item in filteredAgentsDetailedArr">
            <td ng-if="item.name == 'Not Logged'">
                {{ item.name }}
            </td>
            <td ng-if="item.name == 'In Call'" 
                ng-style="{backgroundColor: 'green'}">
                {{ item.name }}
            </td>
            <td ng-if="item.name == 'Waiting'" 
                ng-style="{backgroundColor: 'red'}">
                {{ item.name }}
            </td>

           <td ng-if="item.time_waiting[6] < 3 && item.time_waiting[4] == 0" 
               ng-style="{backgroundColor: 'yellow'}">
               {{ item.time_waiting }}
           </td>
           <td ng-if="item.time_waiting[6] >= 3 && item.time_waiting[4] < 2 ||
                      item.time_waiting[4] == 1 && item.time_waiting[3] == 0"
               ng-style="{backgroundColor: 'gold'}">
               {{ item.time_waiting }}
           <td>
       </tr>
    </tbody>
</table>

也就是说,一切正常。但是我想在整个字符串中添加一个样式(或者可能是ng-class)而不是一个单元格。也许有人知道如何使用ng-if指令实现这一点?
提前谢谢!)

2 个答案:

答案 0 :(得分:0)

使用var newImage = UrlFetchApp.fetch(url).getBlob().getAs('image/png') ng-class指令完成条件样式。

Plase,请查看官方文档:ng-classng-style

答案 1 :(得分:0)

试试这个:

你的HTML

<table>
<thead>
    <tr>
        <td>
            Status
        </td>
        <td>
            Time waiting
        </td>
    </tr>
</thead>
<tbody>
    <tr ng-repeat="item in filteredAgentsDetailedArr"
        ng-class="{ 'incall' : item.name == 'In Call', 'waiting' : item.name == 'Waiting'}">
        <td ng-if="item.name == 'Not Logged'">
            {{ item.name }}
        </td>
        <td ng-if="item.name == 'In Call'">
            {{ item.name }}
        </td>
        <td ng-if="item.name == 'Waiting'">
            {{ item.name }}
        </td>

       <td >
         <span ng-if="item.time_waiting[6] < 3 && item.time_waiting[4] == 0"
               ng-style="{backgroundColor: 'yellow'}">
           {{ item.time_waiting }}
         </span>
       </td>
   </tr>
</tbody>

在你的CSS上

table {
  border-collapse:collapse;
}

.incall {
  background-color: green;
}

.waiting {
  background-color: red;
}