【发布时间】:2017-07-07 01:23:39
【问题描述】:
我从 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 中访问“类型”时,我只得到一个 int 值。但我想得到一个字符串值。
例如:
'message.type=0'
{{message.type}} => should be Info
'message.type=1'
{{message.type}} => should be Warning
【问题讨论】:
-
这是编译时问题还是运行时问题?
-
它编译并运行良好。对于
{{message.type}],我得到0,但我想得到Info。
标签: javascript angular typescript enums