在我的Angular6应用程序,我正在使用Http客户端将一些标头注入到我的 htpp 调用中以从我的后端服务器获取数据:
我的服务:
@Injectable()
export class LoadUserInfosService {
public _headers = new HttpHeaders().set('Content-Type', 'application/json');
constructor(private httpClient: HttpClient) {}
getUserPnsInfos(cuid): Observable<object> {
const headers = this._headers.append('login', login);
return this.httpClient.get(myBackUrl, {headers: headers});
}
}
我订阅的组件:
loadUserInfosFromPns(login) {
this.loadUserInfosService.getUserPnsInfos(login).subscribe(infos => {
let receivedInfos: any;
receivedPnsInfos = infos ;
console.log(receivedPnsInfos);
if (pnsInfos !== null && receivedPnsInfos.cuid === cuid ) {
} else {
this.router.navigate(['unauthorized'], {skipLocationChange: true});
}
},
error => {
console.log(error);
});
}
在 Chrome 或 IE11 上运行时,我收到一些引用我的请求标头的错误:
TypeError: Cannot read property 'length' of null
at HttpHeaders.push../node_modules/@angular/common/fesm5/http.js.HttpHeaders.applyUpdate (http.js:199)
at http.js:170
at Array.forEach (<anonymous>)
at HttpHeaders.push../node_modules/@angular/common/fesm5/http.js.HttpHeaders.init (http.js:170)
at HttpHeaders.push../node_modules/@angular/common/fesm5/http.js.HttpHeaders.forEach (http.js:235)
at Observable._subscribe (http.js:1445)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:161)
at subscribeTo.js:21
at subscribeToResult (subscribeToResult.js:6)
at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._innerSub (mergeMap.js:127)
此错误仅出现在Chrome and IE11- 当在Firefox the 请求康复,但我没有得到
有什么想法、建议吗?