我有一个表格,它使用ng-repeat填充值。我需要用绿色和黄色交替着色表格的行。我尝试了下面的方式没有ng-repeat,它的工作原理。用ng-repeat在html表格中替换行着色
.table-striped>tbody>tr:nth-of-type(odd)
{
background: yellow !important;
}
.table-striped>tbody>tr:nth-of-type(even)
{
background: green !important;
}
<html>
<div><table class="table table-striped">
<thead style="border: 1px solid">
<tr>
<th>Heading</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{value.val1}}</td>
</tr>
<tr>
<td>{{value.val2}}</td>
</tr>
<tr>
<td>{{value.val3}}</td>
</tr>
</tbody>
</table>
</div>
<html>
但同时采用NG-重复如下它不工作(全部行以黄色本身)。请帮助。提前感谢。
.table-striped>tbody>tr:nth-of-type(odd)
{
background: yellow !important;
}
.table-striped>tbody>tr:nth-of-type(even)
{
background: green !important;
}
<html>
<div><table class="table table-striped">
<thead style="border: 1px solid">
<tr>
<th>Heading</th>
</tr>
</thead>
<tbody ng-repeat="value in values">
<tr>
<td>{{value.val1}}</td>
</tr>
</tbody>
</table>
</div>
<html>
给纳克级一试。它应该按预期工作。我怀疑角度只会在第一次渲染后创建值,这会导致CSS不应用样式。 – codemax
我可以看到两者似乎都很好。 – Chetan