DEV Community

Discussion on: Working with Enums in Angular components

Collapse
 
_builtbyjay profile image
Jay Vincent

Nice article!

I Found this when searching for "using enums in Angular templates" as I was getting a type error when doing an AOT build:

Argument of type 'string' is not assignable to parameter of type 'MyEnumName'.
Enter fullscreen mode Exit fullscreen mode

I did indeed need to convert my enum to an array of strings in order to compare against another string value, which I did using Object.values() rather than Object.keys() as mentioned in your article:

public myArray = Object.values(MyEnumName).map(item => String(item));
Enter fullscreen mode Exit fullscreen mode
Collapse
 
shane profile image
Shane McGowan • Edited

Pretty sure .values and .keys will do the same thing if you have your enum declare with a string value as follows

enum PropertyType {
  House = 'House'
}
Enter fullscreen mode Exit fullscreen mode

I assume you just have your enum declared like the below

enum PropertyType {
  House = 'House'
}
Enter fullscreen mode Exit fullscreen mode