只需查看HttpModule
. 您将看到创建Http
. 这些提供者中的大多数是现在被删除的HTTP_PROVIDERS
export function _createDefaultCookieXSRFStrategy() {
return new CookieXSRFStrategy();
}
export function httpFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http {
return new Http(xhrBackend, requestOptions);
}
@NgModule({
providers: [
{provide: Http, useFactory: httpFactory, deps: [XHRBackend, RequestOptions]},
BrowserXhr,
{provide: RequestOptions, useClass: BaseRequestOptions},
{provide: ResponseOptions, useClass: BaseResponseOptions},
XHRBackend,
{provide: XSRFStrategy, useFactory: _createDefaultCookieXSRFStrategy},
],
})
export class HttpModule {
}
只需将上面的所有内容添加providers
到您传递给的数组中ReflectiveInjector.resolveAndCreate
。
如果您的目标是获得Http
before 引导程序,那么您需要处理另一件小事,即CookieXSRFStrategy
. 它在引导之前不起作用,因为它依赖于某些平台浏览器的东西。如本文所述,您可以将其替换为 noop