我想使用一個枚舉值來設置HTML屬性的設定值:Angular2使用枚舉值
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 ;
}
<td><input name="status" type="radio" [value]="MyEnum.FirstValue" [(ngModel)]="myEnumValue"></td>
<td><input name="status" type="radio" [value]="MyEnum.SecondValue" [(ngModel)]="myEnumValue"></td>
但是我得到「無法讀取屬性'FirstValue'未定義「
有沒有辦法使用枚舉值作爲html屬性的值?
https://stackoverflow.com/questions/45799745/pass-enum-value-to-angular-2-component/45800962#45800962 –