I have looked at questions like this one. But it doesn't quite answer my question. I want to bind the local variable name to the enum's value like in the following (heavily simplified) example:
In certain-state.component.ts
:
export enum CertainState {
VALID,
INVALID
}
export class CertainStateComponent {
// holder for the current state
public state: CertainState;
// store the actual enum in the instance of the class so that
// it is available in the template
public certainStates: typeof CertainState = CertainState;
// below is the logic which sets the state
...
}
In certain-state.component.html
:
<ng-container *ngTemplateOutlet="state_{{state}}"></ng-container>
// obviously this is invalid syntax but I want to demonstrate my intention
<ng-template #state_{{certainStates.VALID}}><span>VALID</span></ng-template>
<ng-template #state_{{certainStates.INVALID}}><span>INVALID</span></ng-template>
EDIT: I think the solution is in the following answer: How to use a typescript enum value in an Angular2 ngSwitch statement. What do you guys think?
should be
or