返回RC4我可以使用
创建我的自定义http实例@Injectable()
export class myHttp{
constructor(@Inject('defaultUrl) private url:string, @Inject('defaultHeaders) private headers:Headers, private http:Http){}
get()
put()...
}
myHttp是Http
的包装器{{1}}
现在弃用并删除了HTTP_PROVIDERS,我该如何提供呢?
谢谢!
答案 0 :(得分:3)
@NgModule({
imports: [HttpModule],
...
})
class AppModule {}
或将HTTP_PROVIDERS
的定义从Angular2源复制到您的源代码,并像以前一样在那里使用它。
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()},
];
您也可以使用
这些提供程序自行创建注射器let resolvedProviders = ReflectiveInjector.resolve(HTTP_PROVIDERS);
let injector = ReflectiveInjector.fromResolvedProviders(resolvedProviders, /* this.injector (parent injector if any) */ );
var http = child.get(Http);