When working with Typescript, it's important to understand that enums
are transpiled into JavaScript arrays (refer to Enums in TypeScript: what is the JavaScript code doing?).
If you need to dynamically load an enum, simply load an array instead.
However, if your aim is to generate a select dropdown from this enum, it's recommended to deserialize your JSON and pass it to a component with a nested select
, generating option
s by looping through the object using *ngFor
.
The most straightforward approach involves formatting your JSON like this:
{
"selectData":[
{
"key":"foo",
"value":"bar"
}
]
}
This way, you can easily load your JSON and iterate over the selectData
array, utilizing the key
and value
attributes to populate your select dropdown.