I've got a string enum and a method in my component:
export enum Language {
de = 'de',
en = 'en'
}
setLang(lang: Language.en | Language.de) {
const curent = Language[lang]
}
Than I want to call it in the view:
<button (click)="setLang('en')">
but when I run ng build --prod I've got this error
Argument of type '"en"' is not assignable to parameter of type 'Language'.
I know if I should call in the component it should be
setLang( Language.en) but
how can I call setLang in the view?
UPDATE
All in all I don't like very much passing a reference of my enum to a property class so may be this could be a better approach
type LangKeys = keyof typeof Language;
function foo(lang:LangKeys) {
const curent = Language[lang]
}
foo('en')