小编won*_*yte的帖子

Angular2在html值属性中使用枚举值

我正在尝试使用枚举值来设置HTML属性的选定值:

export enum MyEnum {
    FirstValue,
    SecondValue
}
export function MyEnumAware(constructor: Function) {
    constructor.prototype.MyEnum = MyEnum;
}

@MyEnumAware
@Component({
    templateUrl: "./lot-edit.component.html",
    styleUrls: ["./lot-edit.component.css"],
})
export class LotEditComponent implements OnInit {
    @Input() myEnumValue: MyEnum ;
Run Code Online (Sandbox Code Playgroud)

}

<td><input name="status" type="radio" [value]="MyEnum.FirstValue" [(ngModel)]="myEnumValue"></td>
<td><input name="status" type="radio" [value]="MyEnum.SecondValue" [(ngModel)]="myEnumValue"></td>
Run Code Online (Sandbox Code Playgroud)

但是我得到"无法读取未定义的属性'FirstValue'"

有没有办法使用枚举值作为html属性的值?

enums typescript angular

17
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular ×1

enums ×1

typescript ×1