@NgModule({
imports: [HttpModule],
...
})
class AppModule {}
or copy the definition of HTTP_PROVIDERS
from the Angular2 source to your source and use it there like before.
const HTTP_PROVIDERS = [
{provide: Http, useFactory:
(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http =>
new Http(xhrBackend, requestOptions),
deps: [XHRBackend, RequestOptions]},
BrowserXhr,
{provide: RequestOptions, useClass: BaseRequestOptions},
{provide: ResponseOptions, useClass: BaseResponseOptions},
XHRBackend,
{provide: XSRFStrategy, useFactory: () => new CookieXSRFStrategy()},
];
You can also create an injector yourself using these providers like
let resolvedProviders = ReflectiveInjector.resolve(HTTP_PROVIDERS);
let injector = ReflectiveInjector.fromResolvedProviders(resolvedProviders, /* this.injector (parent injector if any) */ );
var http = child.get(Http);
See also Inject Http manually in angular 2
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…