ShareModule
import { NgModule, ModuleWithProviders } from
'@angular/core'
;
@NgModule({
imports: [
HttpModule,
JsonpModule,
...
],
declarations: [
ShowItDirective,
...
],
exports: [
ShowItDirective,
...
]
})
export class ShareModule{
static forRoot(): ModuleWithProviders {
return
{
ngModule: ShareModule,
providers: [
MessageService,
NotifyService,
... any service
],
};
}
}
AppModule
@NgModule({
declarations: [
AppComponent,
],
imports: [
ShareModule.forRoot(),
],
providers: [
],
bootstrap: [AppComponent]
})
export class AppModule { }