Add description attribute to enum and read this description in Angular

Create enum File

Create a file in the named like enums.enum.ts. Add in a Enum:

export enum Fruits{
    Apple= 1,
    Oranges = 2
}

Create the Constant File

Create a file in the named like constants.ts. Add in a Enum constant for description :

export const FruitsLabel = new Map([
  [Fruits.Apple, 'Yummy Apples'],
  [Fruits.Oranges , 'Big Oranges']
]);

Load the Constant in the Component

import {FruitsLabel} from './Constants';

ngOnInit(): void 
{
console.log(FruitsLabel.get(Fruits.Apple));
}

return // Yummy Apples
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments