import { NgModule, Optional, SkipSelf } from '@angular/core'; import { HttpClientModule } from '@angular/common/http'; import { HttpClientXsrfModule } from '@angular/common/http'; import { throwIfAlreadyLoaded, NaTranslateModule, NA_TRANSLATE_RESOURCES } from '@ng-arthur-mobile/core'; import { NaHttpService } from './na-http.service'; import { OverlayModule } from '@angular/cdk/overlay'; import { HttpTranslateLoader } from './interceptor/http-translate-loader'; import { NA_HTTP_INTERCEPTOR_PREPARABLE, NaHttpInterceptorPreparableHandler } from './interceptor/na-http-interceptor-preparable'; import { NaBaseurlInterceptorPreparable } from './interceptor/support/na-baseurl-interceptor-preparable'; import { Noop } from './interceptor/support/test'; import { NaParamsInterceptorPreparable } from './interceptor/support/na-params-interceptor-preparable'; export function TranslateResource() { return new HttpTranslateLoader(); } /** * HTTP模块,该模块只允许导入一次! * * @export */ @NgModule({ imports: [ OverlayModule, HttpClientModule, NaTranslateModule, HttpClientXsrfModule.withOptions({ cookieName: 'NA-XSRF-TOKEN', headerName: 'NA-X-XSRF-TOKEN', }) ], exports: [ HttpClientModule ], providers: [ NaHttpService, NaHttpInterceptorPreparableHandler, { provide: NA_TRANSLATE_RESOURCES, useFactory: TranslateResource, multi: true }, { provide: NA_HTTP_INTERCEPTOR_PREPARABLE, useClass: NaBaseurlInterceptorPreparable, deps: [NaHttpService], multi: true }, { provide: NA_HTTP_INTERCEPTOR_PREPARABLE, useClass: NaParamsInterceptorPreparable, deps: [NaHttpService], multi: true }, { provide: NA_HTTP_INTERCEPTOR_PREPARABLE, useClass: Noop, multi: true }, ] }) export class NaHttpModule { constructor(@Optional() @SkipSelf() parentModule: NaHttpModule) { throwIfAlreadyLoaded(parentModule, 'NaHttpModule'); } }