Skip to content

Instantly share code, notes, and snippets.

@kmaida
Last active November 12, 2017 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmaida/cbdc8ff92d52385eb4a6ece531003446 to your computer and use it in GitHub Desktop.
Save kmaida/cbdc8ff92d52385eb4a6ece531003446 to your computer and use it in GitHub Desktop.
Sharing module with providers in Angular (i.e., https://alligator.io/angular/providers-shared-modules/)
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CoreModule } from './core/core.module';
@NgModule({
declarations: [],
imports: [
BrowserModule,
CoreModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SomeSharedService } from './shared.service';
@NgModule({
imports: [
CommonModule
],
declarations: []
})
export class CoreModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: CoreModule,
providers: [
SomeSharedService
]
};
}
}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CoreModule } from './../../core/core.module';
import { RouterModule } from '@angular/router';
import { SOME_ROUTES } from './some.routes';
import { SomeComponent } from './some-component/some.component';
@NgModule({
imports: [
CommonModule,
CoreModule,
RouterModule.forChild(SOME_ROUTES)
],
declarations: [
SomeComponent
]
})
export class LazyLoadedModule { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment