有一个问题。
在给枚举属性分配枚举值时,出现错误:类型“string”不能赋值给类型“CountryCode”。
我认为不应该出现这种情况,因为属性和值都是相同的enum
类型。
enum
属性的服务:
@Injectable()
export class UserData {
private _country_code: CountryCode;
private _currency_code: CurrencyCode;
constructor() { }
get country_code(): CountryCode {
return this._country_code;
}
set country_code(value: CountryCode) {
this._country_code = value;
}
get currency_code(): CurrencyCode {
return this._currency_code;
}
set currency_code(value: CurrencyCode) {
this._currency_code = value;
}
}
枚举
export enum CountryCode {
TH,
BGD,
}
使用案例出现错误:
this.userData.country_code = CountryCode[data.country_code];