-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.module.ts
38 lines (35 loc) · 1.43 KB
/
api.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core';
import { Configuration } from './configuration';
import { HttpClient } from '@angular/common/http';
import { BlobsService } from './api/blobs.service';
import { CertificatesService } from './api/certificates.service';
import { CollectionsService } from './api/collections.service';
import { DevicesService } from './api/devices.service';
import { FotaService } from './api/fota.service';
import { GatewaysService } from './api/gateways.service';
import { OutputsService } from './api/outputs.service';
import { SpanService } from './api/span.service';
@NgModule({
imports: [],
declarations: [],
exports: [],
providers: []
})
export class ApiModule {
public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders<ApiModule> {
return {
ngModule: ApiModule,
providers: [ { provide: Configuration, useFactory: configurationFactory } ]
};
}
constructor( @Optional() @SkipSelf() parentModule: ApiModule,
@Optional() http: HttpClient) {
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');
}
}
}