HttpClientModule

An NgModule that provides the HttpClient and associated services.

一个 NgModule,可以提供 HttpClient 及其相关服务。

class HttpClientModule { }

说明

Interceptors can be added to the chain behind HttpClient by binding them to the multiprovider for HTTP_INTERCEPTORS.

通过把拦截器提供为 HTTP_INTERCEPTORS(允许有多个),可以把它们添加到 HttpClient 调用链的后面。

注解

@NgModule({ imports: [ HttpClientXsrfModule.withOptions({ cookieName: 'XSRF-TOKEN', headerName: 'X-XSRF-TOKEN' }), ], providers: [ HttpClient, { provide: HttpHandler, useClass: HttpInterceptingHandler }, HttpXhrBackend, { provide: HttpBackend, useExisting: HttpXhrBackend }, BrowserXhr, { provide: XhrFactory, useExisting: BrowserXhr }, ] })