Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 {
}
like image 654
Christoph Glaß Avatar asked Sep 26 '17 06:09

Christoph Glaß


2 Answers

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

like image 138
Suren Srapyan Avatar answered Sep 27 '22 23:09

Suren Srapyan


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

export const enum <ENUM_NAME>
like image 39
Amine Safi Avatar answered Sep 27 '22 22:09

Amine Safi