【发布时间】:2021-07-04 21:51:57
【问题描述】:
我正在开发一个 Angular 应用程序。我有一个枚举如下
export class myEnum {
"status1" = 1,
"status2" = 2,
"status3" = 3,
"status4" = 4,
"status5" = 5
}
在我的 html 中,我有一个来自 api 的数据,我正在使用 *ngFor 来显示它,如下所示:
<div>*ngFor="let mydata of data"</div>
现在这个数据将有一个整数状态字段(可以使用 {{mydata.status}} 访问),它将与上述枚举匹配。在我的 html 中,我想传递/匹配这个数字并将其显示为字符串。假设从 API 中,如果状态为 4,那么我想要一个代码,我在其中传递这个值,它应该在枚举中匹配它并在屏幕上显示“status4”。我该怎么做?
【问题讨论】: