Assume I have a const enum:
export const enum MyConstEnum{
Value1 = 'Value1',
Value2 = 'Value2',
Value3 = 'Value3'
}
Now I want to use it in my Angular template:
<span *ngIf="name === MyConstEnum.Value1">This has some value</value>
However, this is not possible, because MyConstEnum
is not seen by template.
So the question is how to access const enum
in Angular html template?
If enum won't be const like this
export enum MyEnum{
Value1 = 'Value1',
Value2 = 'Value2',
Value3 = 'Value3'
}
there is a solution to create property in templates' component
public get MyEnumInComponent() {
return MyEnum;
}
and MyEnumInComponent
will be accessible in HTML.
However, I have const enum
.
For this I cannot defined property like above. What is the solution (except changing const enum
to enum
)?
I can see on this link https://github.com/angular/angular/issues/25963 that it is known issue and it is specifically with const enum.
There is also a work arround suggested in the discussion on the url:
templateImports: [someConstant, UserStatus, isDevMode]
This would not work, but the below could:
templateImports: {someConstant, UserStatus, isDevMode}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With