您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

32 行
1.0KB

  1. import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core';
  2. import { Configuration } from './configuration';
  3. import { HttpClient } from '@angular/common/http';
  4. import { RulesService } from './api/rules.service';
  5. @NgModule({
  6. imports: [],
  7. declarations: [],
  8. exports: [],
  9. providers: []
  10. })
  11. export class ApiModule {
  12. public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders<ApiModule> {
  13. return {
  14. ngModule: ApiModule,
  15. providers: [ { provide: Configuration, useFactory: configurationFactory } ]
  16. };
  17. }
  18. constructor( @Optional() @SkipSelf() parentModule: ApiModule,
  19. @Optional() http: HttpClient) {
  20. if (parentModule) {
  21. throw new Error('ApiModule is already loaded. Import in your base AppModule only.');
  22. }
  23. if (!http) {
  24. throw new Error('You need to import the HttpClientModule in your AppModule! \n' +
  25. 'See also https://github.com/angular/angular/issues/20575');
  26. }
  27. }
  28. }