Like m32da1 says, the Service is only used in the CrisisCenterModule. What I did lazy load my routes:
export const routes: Routes = [
{ path: '', redirectTo: 'login', pathMatch: 'full' },
{ path: 'crisis', loadChildren: 'app/crisis-center/crisisCenter.module' }
...
and add the CrisisServices as a provider in the crisisCenter module
If you are planning to use it in other components/routes as well, you can make it an singleton: https://angular.io/docs/ts/latest/guide/ngmodule.html#!#shared-module-for-root
Add a shared.module.ts
import { NgModule, ModuleWithProviders } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HeroesModule } from './heroes/heroes.module';
import { LoginComponent } from './login.component';
import { DialogService } from './dialog.service';
import { CrisisService } from './crisis-center/crisis.service';
@NgModule({
imports: [CommonModule, FormsModule, RouterModule ],
declarations: [],
exports: [
CommonModule, FormsModule, RouterModule]
})
export class SharedModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: SharedModule,
providers: [DialogService, CrisisService],
};
}
}
And add the SharedModule.forRoot to the imports in the app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { routing,
appRoutingProviders } from './app.routing';
import { HeroesModule } from './heroes/heroes.module';
import { LoginComponent } from './login.component';
import { DialogService } from './dialog.service';
@NgModule({
imports: [
BrowserModule,
SharedModule.forRoot(),
routing,
HeroesModule
],
declarations: [
AppComponent,
LoginComponent
],
providers: [
appRoutingProviders
],
bootstrap: [ AppComponent ]
})
export class AppModule {
}