我正在尝试使用枚举值来设置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属性的值?