Angular 如何在同一个表中设置最小值和最大值的样式?
Angular 如何在同一个表中设置最小值和最大值的样式?,angular,Angular,代理ID 国家 地址 日期 {{item.agent}} {{item.country} {{item.address} {{item.date} {{resolvedAgents?.length}任务 您可以添加一个新的属性,也可以创建一个新的索引变量来指示哪个元素是max或min(任何类别) 然后将其绑定到样式,然后将其作为ngFor索引与最大或最小索引值的条件 minIdx = null; maxIdx = null; ngOnInit() { this.minIdx
代理ID
国家
地址
日期
{{item.agent}}
{{item.country}
{{item.address}
{{item.date}
{{resolvedAgents?.length}任务
您可以添加一个新的属性,也可以创建一个新的索引变量来指示哪个元素是max或min(任何类别)
然后将其绑定到样式,然后将其作为ngFor索引与最大或最小索引值的条件
minIdx = null;
maxIdx = null;
ngOnInit() {
this.minIdx = 1;
this.maxIdx = 2;
}
<tr *ngFor="let item of resolvedAgents; let i = index"
[style.background-color]="i === minIdx ? 'red':'blue'">
<td>{{item.agent}}</td>
<td>{{item.country}}</td>
<td>{{item.address}}</td>
<td>{{item.date}}</td>
</tr>
@兰科维奇很好的解决方案!
(i === minIdx) ? 'red': (i === maxIdx) ? 'blue' : 'white'