【发布时间】:2021-06-12 00:57:46
【问题描述】:
我有一个循环通过设备的 *ngFor 循环,这些设备连接到实时数据库。我的代码检查设备上次联机的时间并将其标记为脱机或联机。现在由于某种原因,“ion-select-option”无法通过样式访问它,而是在 global.scss 中被选中,如下所示:
ion-alert.
select-alert {
--background: red!important;
// --color: red !important;
button {
color: white !important;
font-size: 20px !important;
}
.sc-ion-alert-md {
color: red;
}
}
这行不通,因为我需要动态的颜色。下面是一个 sn-p 代码,我在其中尝试通过一组颜色 levelColors 进行更改
public levelColors: { [level: string]: string } = {
Alert: "grey",
online: "green",
Level2: "blue",
Level3: "orange",
offline: "red",
};
我觉得其余的都是不言自明的,所以我的问题是......有没有办法为选项着色或者我应该选择不同的解决方案?
<ion-select [(ngModel)]="vehicleSelection" (ionChange)="onSelectChange($event)">
<ion-select-option *ngFor="let vehicle of vehicleArray" [value]="vehicle"
[style.color]="levelColors[vehicle.stat]">
{{vehicle.fleet_nr}} [{{vehicle.reg_nr}}]
{{levelColors[vehicle.stat]}}
</ion-select-option>
</ion-select>
【问题讨论】:
标签: html ionic-framework