Angular 4 export enum type from library/dependency

3.5k views Asked by At

I want to make a library to use in my Angular 4 applications, and for some business I will do on it I have an enum that the applications will need to use later. Problem is, I declare the enum like this in my-enum.ts:

export enum MyEnum {
    value1 = 1,
    value2 = 2,
    value3 = 3
}

But then, I can't seem to import it from my app when I do the following:

import { MyEnum } from 'my-library';

How should I proceed to have this correctly?

2

There are 2 answers

0
altc On

I had the same issue, but I simply forgot to build my library before trying to use the exported enum (ng build --prod my-library).

0
A.S On

If you are writing Angular libraries, you have to export enums with the keyword const

export const enum <ENUM_NAME>