在Typescript中将int转换为枚举字符串
- 论坛
- 在Typescript中将int转换为枚举字符串
28 浏览
在Typescript中将int转换为枚举字符串
我从一个RESTful服务获取到以下数据:
[
{
"id": 42,
"type": 0,
"name": "Piety was here",
"description": "Bacon is tasty, tofu not, ain't nobody like me, cause i'm hot..."
}...
我使用以下类进行映射:
export enum Type { Info, Warning, Error, Fatal } export class Message{ public id: number; public type: Type: public name: string; public description: string; }
但是当我在Angular2中访问'type'时,我只得到一个整数值。但是我希望得到一个字符串值。
例如:
'message.type=0' {{message.type}} => 应该是"Info" 'message.type=1' {{message.type}} => 应该是"Warning"