I've this...myservice.service.ts:
import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { ReqLogin, ResLogin, ResList} from '../../interfaces/general';
import { GlobalService} from '../global/global.service';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/do';
...
list(): Observable<ResList> {
const url = this.gs.backendServer + this.gs.backend.endpoints.list;
const httpOptions = {
headers: new HttpHeaders({
'Authorization': this.gs.token
})
};
return this.http.get(url, httpOptions)
.map(res => <ResList> res)
.do(dataReceived => console.log(dataReceived));
}
This works fine, the server receive the reader, I receive the data from server, but I receive also this exception:
ERROR TypeError: Cannot read property 'length' of undefined
at eval (http.js:123)
at Array.forEach (<anonymous>)
at HttpHeaders.lazyInit (http.js:117)
at HttpHeaders.init (http.js:265)
at HttpHeaders.forEach (http.js:368)
at Observable.eval [as _subscribe] (http.js:2172)
at Observable._trySubscribe (Observable.js:172)
at Observable.subscribe (Observable.js:160)
at subscribeToResult (subscribeToResult.js:23)
at MergeMapSubscriber._innerSub (mergeMap.js:138)
if I drop the Http Options, this works perfect.
any clue ?