2019-01-22 14:11:35 -05:00
|
|
|
// #docregion whole-greeting-module
|
|
|
|
import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
|
|
|
|
|
|
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
|
|
|
|
import { GreetingComponent } from './greeting.component';
|
|
|
|
import { UserServiceConfig } from './user.service';
|
|
|
|
|
|
|
|
|
|
|
|
@NgModule({
|
|
|
|
imports: [ CommonModule ],
|
|
|
|
declarations: [ GreetingComponent ],
|
|
|
|
exports: [ GreetingComponent ]
|
|
|
|
})
|
|
|
|
export class GreetingModule {
|
|
|
|
// #docregion ctor
|
2020-07-30 13:03:10 +03:00
|
|
|
constructor(@Optional() @SkipSelf() parentModule?: GreetingModule) {
|
2019-01-22 14:11:35 -05:00
|
|
|
if (parentModule) {
|
|
|
|
throw new Error(
|
|
|
|
'GreetingModule is already loaded. Import it in the AppModule only');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// #enddocregion ctor
|
|
|
|
|
|
|
|
// #docregion for-root
|
2020-05-01 16:39:22 -07:00
|
|
|
static forRoot(config: UserServiceConfig): ModuleWithProviders<GreetingModule> {
|
2019-01-22 14:11:35 -05:00
|
|
|
return {
|
|
|
|
ngModule: GreetingModule,
|
|
|
|
providers: [
|
|
|
|
{provide: UserServiceConfig, useValue: config }
|
|
|
|
]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// #enddocregion for-root
|
|
|
|
}
|
|
|
|
// #enddocregion whole-greeting-module
|