问题描述
在我的 Angular6 应用下,我正在使用 HttpClient 向我的htpp调用注入一些标头来从我的后端服务器获取数据:
Under my Angular6 app , i'm using HttpClient with some headers injection to my htpp calls to fetch data from my backend server :
我的服务:
My service :
@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上运行时我收到一些错误,提到我的请求header:
when running on Chrome or IE11 i'm getting some error refering to my request headers:
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 和 IE11 中 - 在 Firefox 下 请求变好,我没有得到它
this error appears only in Chrome and IE11 - while under Firefox the request get well and i'm not getting it
有任何想法,建议吗?
推荐答案
这可能是因为您正在设置undefined / null标头在一些http请求中。
It is probably caused because you are settting an undefined / null header in some http request.
这篇关于Angular 6:HttpHeaders无法在Chrome和IE11中读取null的属性“长度”(而不是在Firefox中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!