How to use a typescript enum value in an Angular2 ngSwitch statement

The Typescript enum seems a natural match with Angular2’s ngSwitch directive. But when I try to use an enum in my component’s template, I get “Cannot read property ‘xxx’ of undefined in …”. How can I use enum values in my component template?

Please note that this is different from how to create html select options based upon ALL of the values of an enum (ngFor). This question is about ngSwitch based upon a particular value of an enum. Although the same approach of creating an class-internal reference to the enum appears.

10 Answers
10

Leave a Comment