Christoph Glaß
Christoph Glaß

Reputation: 209

Exporting enums in Angular modules

Does anyone know if it’s possible to export enums in Angular modules? If not, are there any best practises to ship enums within Angular modules?

// not working example
// i dont know how to export GreatEnum

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { GreatComponent } from './great.component';
import { GreatEnum } from './great.enum';

@NgModule({
    imports: [
        CommonModule       
    ],
    declarations: [GreatComponent ],
    exports: [GreatComponent ]
})
export class GreatModule {
}

Upvotes: 8

Views: 16599

Answers (2)

A.S
A.S

Reputation: 289

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

export const enum <ENUM_NAME>

Upvotes: 10

Suren Srapyan
Suren Srapyan

Reputation: 68665

Why you need to export enum from the modules?. It is not necessary . It is like an interfaces and classes. You can use it everywhere, except directly in the templates.

You can just import them in any file which you want and use there. For them there is no error like

Directive or Component is not found

Upvotes: 8

Related Questions