Last active
November 12, 2017 18:36
-
-
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/)
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
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 { } |
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
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 | |
] | |
}; | |
} | |
} |
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
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