Skip to content

Instantly share code, notes, and snippets.

@sajidali
Last active June 21, 2019 19:02
Show Gist options
  • Save sajidali/017df3246e4dba7d2c2c465c3dfbd0f0 to your computer and use it in GitHub Desktop.
Save sajidali/017df3246e4dba7d2c2c465c3dfbd0f0 to your computer and use it in GitHub Desktop.
coreModuleExample ❤
/* 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