Let's say I define an enum like this:
export enum SomeEnum {
SomeLongName = 1,
AnotherName = 2
}
Within my display components, I'm utilizing an enum map to translate the enum values into strings for presentation on the web app:
enumMap = new Map<number, string>([
[SomeEnum.SomeLongName, 'Some long name.'],
[SomeEnum.AnotherName, 'Another name.']
]);
While it functions correctly within the component, my intention is to reuse this map in other components. However, when attempting to declare it in my whatever.model.ts
file, I encounter the following error:
Uncaught TypeError: iterable for Map should have array-like objects
I am exporting it in this manner:
export const SomeEnumMap = new Map<number, string>([
[SomeEnum.SomeLongName, 'Some long name.'],
[SomeEnum.AnotherName, 'Another name.']
])
and in my whatever.component.ts
:
import { SomeEnumMap } from './whatever.model.ts';
export class SomeClassComponent implements OnInit {
map = SomeEnumMap;
----------
How can I properly export it so I can reuse it? Generating the map within the component itself works fine, but encountering errors when trying to export it from the model. Unfortunately, Google and the documentation have not provided much guidance.