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 './greatponent';
import { GreatEnum } from './great.enum';
@NgModule({
imports: [
CommonModule
],
declarations: [GreatComponent ],
exports: [GreatComponent ]
})
export class GreatModule {
}
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 {
}
Share
Improve this question
edited Sep 26, 2017 at 6:41
jonrsharpe
122k30 gold badges266 silver badges473 bronze badges
asked Sep 26, 2017 at 6:34
Christoph GlaßChristoph Glaß
2091 gold badge3 silver badges12 bronze badges
6
- 2 show your enum file – porgo Commented Sep 26, 2017 at 6:37
- Like classes: stackoverflow.com/a/46245869/5468463 – Vega Commented Sep 26, 2017 at 6:39
- What do you think you need to export? Why would you want to inject it using DI? – jonrsharpe Commented Sep 26, 2017 at 6:42
- 1 The enum file looks just like: export enum GreatEnum { 'foo' = 1, 'bar' = 2 } – Christoph Glaß Commented Sep 26, 2017 at 6:55
- 1 In case you are looking how to use enums from a subcompent into the parents component - stackoverflow.com/questions/35923744/… – Mauricio Gracia Gutierrez Commented Jun 4, 2021 at 15:41
2 Answers
Reset to default 10If you are writing libraries, you have to export enums with the keyword const
export const enum <ENUM_NAME>
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