docs: fix/improve example for singleton-services
guide (#21589)
PR Close #21589
This commit is contained in:

committed by
Miško Hevery

parent
81e87095b4
commit
4596b9d0df
@ -4,22 +4,20 @@ import { FormsModule } from '@angular/forms';
|
||||
import { HttpModule } from '@angular/http';
|
||||
|
||||
/* App Root */
|
||||
import { AppComponent } from './app.component';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
/* Feature Modules */
|
||||
import { ContactModule } from './contact/contact.module';
|
||||
import { CoreModule } from './core/core.module';
|
||||
import { ContactModule } from './contact/contact.module';
|
||||
// #docregion import-for-root
|
||||
import { CoreModule } from './core/core.module';
|
||||
// #enddocregion import-for-root
|
||||
|
||||
/* Routing Module */
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
|
||||
|
||||
|
||||
// #docregion import-for-root
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AppComponent
|
||||
],
|
||||
// #docregion import-for-root
|
||||
imports: [
|
||||
BrowserModule,
|
||||
ContactModule,
|
||||
@ -28,6 +26,11 @@ import { AppRoutingModule } from './app-routing.module';
|
||||
],
|
||||
// #enddocregion import-for-root
|
||||
providers: [],
|
||||
declarations: [
|
||||
AppComponent
|
||||
],
|
||||
bootstrap: [AppComponent]
|
||||
// #docregion import-for-root
|
||||
})
|
||||
export class AppModule { }
|
||||
// #enddocregion import-for-root
|
||||
|
@ -1,31 +1,34 @@
|
||||
/* tslint:disable:member-ordering no-unused-variable */
|
||||
// #docregion whole-core-module
|
||||
import {
|
||||
ModuleWithProviders, NgModule,
|
||||
Optional, SkipSelf } from '@angular/core';
|
||||
// #docregion whole-core-module
|
||||
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
|
||||
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { TitleComponent } from './title.component';
|
||||
import { UserService } from './user.service';
|
||||
import { TitleComponent } from './title.component';
|
||||
// #docregion user-service
|
||||
import { UserService } from './user.service';
|
||||
// #enddocregion user-service
|
||||
import { UserServiceConfig } from './user.service';
|
||||
|
||||
|
||||
// #docregion user-service
|
||||
@NgModule({
|
||||
// #enddocregion user-service
|
||||
imports: [ CommonModule ],
|
||||
declarations: [ TitleComponent ],
|
||||
exports: [ TitleComponent ],
|
||||
// #docregion user-service
|
||||
providers: [ UserService ]
|
||||
})
|
||||
export class CoreModule {
|
||||
// #docregion ctor
|
||||
// #enddocregion user-service
|
||||
// #docregion ctor
|
||||
constructor (@Optional() @SkipSelf() parentModule: CoreModule) {
|
||||
if (parentModule) {
|
||||
throw new Error(
|
||||
'CoreModule is already loaded. Import it in the AppModule only');
|
||||
}
|
||||
}
|
||||
// #enddocregion ctor
|
||||
|
||||
// #enddocregion ctor
|
||||
|
||||
// #docregion for-root
|
||||
static forRoot(config: UserServiceConfig): ModuleWithProviders {
|
||||
@ -36,9 +39,8 @@ export class CoreModule {
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
// #enddocregion for-root
|
||||
// #docregion user-service
|
||||
}
|
||||
|
||||
// #enddocregion user-service
|
||||
// #enddocregion whole-core-module
|
||||
|
||||
|
Reference in New Issue
Block a user