Last active
June 21, 2019 19:02
-
-
Save sajidali/017df3246e4dba7d2c2c465c3dfbd0f0 to your computer and use it in GitHub Desktop.
coreModuleExample ❤
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 3rd party libraries */ | |
import { NgModule, Optional, SkipSelf } from '@angular/core'; | |
import { CommonModule } from '@angular/common'; | |
import { HttpClientModule } from '@angular/common/http'; | |
/* our own custom services */ | |
import { SomeSingletonService } from './some-singleton/some-singleton.service'; | |
@NgModule({ | |
imports: [ | |
/* 3rd party libraries */ | |
CommonModule, | |
HttpClientModule, | |
], | |
declarations: [], | |
providers: [ | |
/* our own custom services */ | |
SomeSingletonService | |
] | |
}) | |
export class CoreModule { | |
/* make sure CoreModule is imported only by one NgModule the AppModule */ | |
constructor ( | |
@Optional() @SkipSelf() parentModule: CoreModule | |
) { | |
if (parentModule) { | |
throw new Error('CoreModule is already loaded. Import only in AppModule'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment