I have defined a string enum and a method within my component:
export enum Language {
de = 'de',
en = 'en'
}
setLang(lang: Language.en | Language.de) {
const current = Language[lang]
}
Next, I want to invoke this method in the view:
<button (click)="setLang('en')">
However, when I attempt to build using ng build --prod, an error is triggered:
An argument of type '"en"' cannot be assigned to a parameter of type 'Language'.
I understand that the correct way to call it in the component would be:
setLang( Language.en) but
how can I invoke setLang in the view?
UPDATE
In general, I am not very keen on passing a reference of my enum to a property class, so perhaps a different approach could be better:
type LangKeys = keyof typeof Language;
function foo(lang:LangKeys) {
const current = Language[lang]
}
foo('en')