angular2 resolveAndCreate HTTP – missing HTTP_PROVIDERS in RC7

tornando in RC4 quando esistevano HTTP_PROVIDERS, potevo creare la mia istanza http personalizzata usando

export function createHTTP(url:string, headers?:Headers){ let injector = ReflectiveInjector.resolveAndCreate([ myHttp, {provide:'defaultUrl', useValue:url}, {provide:'defaultHeaders', useValue:headers || new Headers()}, ...HTTP_Providers ]) return injector.get(myHttp) } 

myHttp era un wrapper per Http

 @Injectable() export class myHttp{ constructor(@Inject('defaultUrl) private url:string, @Inject('defaultHeaders) private headers:Headers, private http:Http){} get() put()... } 

Ora con HTTP_PROVIDERS deprecato e rimosso, come posso fornire?

Grazie!

 @NgModule({ imports: [HttpModule], ... }) class AppModule {} 

oppure copia la definizione di HTTP_PROVIDERS dal sorgente Angular2 alla tua fonte e usala lì come prima.

 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()}, ]; 

Puoi anche creare un iniettore usando questi fornitori come

 let resolvedProviders = ReflectiveInjector.resolve(HTTP_PROVIDERS); let injector = ReflectiveInjector.fromResolvedProviders(resolvedProviders, /* this.injector (parent injector if any) */ ); var http = child.get(Http); 

Vedi anche Inject Http manualmente in angular 2