In an Angular4 app, I use a service to export some constants, enums and interfaces used all across the application. I'd like to export an array of strings whose keys are the keys in an anum. This is what I have right now:
export enum ContextMenus {
... (more options)
OBJECT_COLOR_RED = 120,
OBJECT_COLOR_GREEN = 121,
OBJECT_COLOR_BLUE = 122
}
I'd like to export an array of strings based on the values of the enum above, like this:
let ObjectStyles : string[];
ObjectStyles[ContextMenus.OBJECT_COLOR_RED] = '#f00';
ObjectStyles[ContextMenus.OBJECT_COLOR_GREEN] = '#0f0'
ObjectStyles[ContextMenus.OBJECT_COLOR_BLUE] = '#00f';
export ObjectStyles; // THIS IS WHAT I DON'T KNOW HOW TO WRITE
I've tried using export default RulesStyles as suggested in a forum, but when I try to import it from a component like this:
import { ContextMenus, ObjectStyles } from '../app-options.service';
The compiler complains that the module 'app-options.service has no exported member ObjectStyles'.
Another proposed solution was to export ObjectStyles like this:
export { ObjectStyles };
In this case, the compiler doesn't complain, but the app crashes at runtime with the following error:
TypeError: ObjectStyles is undefined
How could I do what I want? Thanks!