我正在使用离子3在股市应用中工作。我需要比较物体当前值和之前值的比率,并需要更新背景颜色。我目前编写的代码如下所示,但有时颜色变化反映,大多数时候颜色没有反映。
export class HomePage {
liverates: any = [];
oldliverates: any = [];
ionViewDidLoad() {
this.liverateservice.setcallback((data)=>{
this.oldliverates = Object.create(this.liverates);
let currentliverates: any = [];
this.commodities.forEach((value, key) => {
currentliverates.push({ 'com_id': com_id, 'com_name': com_name, 'buying_rate': buying_rate, 'selling_rate': selling_rate, 'delivery': deliverydays, 'is_coin': is_coin, 'comname_type': comname_type, 'comnametype_status': comnametype_status, 'deliverydays': deliverydays });
});
this.liverates = currentliverates;
});
}
}
在我看来
<div *ngFor="let liverate of liverates; let i = index">
<ion-row>
<ion-col col-10 class="ratecol div_userwelcome trade_products_name">{{liverate.com_name}}</ion-col>
</ion-row>
<ion-row>
<ion-col col-10 class="ratebox ratecol" [ngClass]="{'ratehigh' : (liverate.selling_rate > oldliverates[i].selling_rate), 'ratelow':(liverate.selling_rate < oldliverates[i].selling_rate), 'ratenormal': (liverate.selling_rate == oldliverates[i].selling_rate)}" (click)="gotoBookingPage(liverate.com_id, '1');">
<div class="rates">{{liverate.selling_rate}}</div>
<div class="sell_rtgs">{{liverate.comname_type}}</div>
</ion-col>
</ion-row>
</div>
我的css,
.ratehigh{
background: #008000;
color: #FFFFFF;
}
.ratelow{
background: #FF0000;
color: #FFFFFF;
}
.ratenormal{
background:null;
color: #000000;
}
当我在登录控制台时,它显示不同的liverate率和oldliverates对象值,如果值得到更新,但不是所有的时间率比较在我的html文件中运行良好。能不能请任何人帮我解决这个问题。