问题描述:在Angular 4中,使用枚举进行选择时,选中值不起作用。
解决方法:
export enum Fruit {
Apple = 'apple',
Banana = 'banana',
Orange = 'orange'
}
import { Fruit } from './fruit.enum';
export class AppComponent {
selectedFruit: Fruit;
}
import { Fruit } from './fruit.enum';
export class AppComponent {
Fruit = Fruit;
}
这样,当用户选择一个选项时,selectedFruit变量将存储选中的枚举值,可以在组件中进一步处理。