import { NgModule , ModuleWithProviders , SkipSelf , Optional } from '@angular/core' ; import { Configuration } from './configuration' ; import { HttpClient } from '@angular/common/http' ; import { AppService } from './api/app.service' ; import { AuthService } from './api/auth.service' ; import { CmsService } from './api/cms.service' ; import { MockService } from './api/mock.service' ; @ NgModule ( { imports : [ ] , declarations : [ ] , exports : [ ] , providers : [ AppService , AuthService , CmsService , MockService ] } ) export class ApiModule { public static forRoot ( configurationFactory ) { return { ngModule : ApiModule , providers : [ { provide : Configuration , useFactory : configurationFactory } ] } ; } constructor ( @ Optional ( ) @ SkipSelf ( ) parentModule , @ Optional ( ) http ) { if ( parentModule ) { throw new Error ( 'ApiModule is already loaded. Import in your base AppModule only.' ) ; } if ( ! http ) { throw new Error ( 'You need to import the HttpClientModule in your AppModule! \n' + 'See also https://github.com/angular/angular/issues/20575' ) ; } } }