There was possibility to extend Http or BaseRequestOptions in RC4 and add default headers to all http requests. Like here How to set default HTTP header in Angular2? How to do it in RC5 ?
Found export declare function httpFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http;
in http.d.ts line 163. Maybe it can help.
答案 0 :(得分:0)
You still can use CustomRequestOptions just like in RC4:
@NgModule({
imports: [...],
providers: [provide(RequestOptions, { useClass: CustomRequestOptions}) ],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
import { Headers, RequestOptions, RequestOptionsArgs } from '@angular/http';
export class CustomRequestOptions extends RequestOptions {
merge(options?: RequestOptionsArgs): RequestOptions {
let headers = new Headers({ 'Content-Type': 'application/json' });
options.headers = headers;
var result = super.merge(options);
result.merge = this.merge;
return result;
}
return super.merge(options);
}
}