I'm using Angular 2 final version and I search a lot about my question but I did not find something that works for angular 2 final. How to add a global header and withCredentials = true for every Http requests at Angular 2 final?
Asked
Active
Viewed 592 times
2
-
Possible duplicate of [Angular2 - set headers for every request](http://stackoverflow.com/questions/34464108/angular2-set-headers-for-every-request) – jcamelis Sep 29 '16 at 15:08
-
@jcamelis that is not for angular 2 final, the things changed since from RC5 – Gustavo Lira Sep 29 '16 at 15:25
1 Answers
0
I could figured out how to this. Just add a new provider at you main module (app.module.ts)
{
provide: Http,
useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
defaultOptions.withCredentials = true;
defaultOptions.headers.append('Content-Type', 'application/json;charset=UTF-8');
defaultOptions.headers.append('Accept', 'application/json;charset=UTF-8');
return new Http(backend, defaultOptions)},
deps[XHRBackend, RequestOptions]
}

Gustavo Lira
- 391
- 5
- 19