![](/img/trans.png)
[英]Error when run a http.get multiples times - Cannot read property 'get' of undefined - Angular
[英]Angular 5 HTTP.get returns cannot read length of undefined
正在通過我的服務進行此調用,以檢索URL以下載文檔:
return this.http.get(this.buildUrl('issueDocument', 'get', pathParams), { responseType: 'blob', params: queryParams });
我已經測試過this.http.get中的buildURL正常工作,但是this.http.get的返回引發此錯誤
ERROR TypeError: Cannot read property 'length' of undefined
at HttpHeaders.applyUpdate (http.js:322)
at eval (http.js:269)
at Array.forEach (<anonymous>)
at HttpHeaders.init (http.js:269)
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 CatchOperator.call (catchError.js:80)
at Observable.subscribe (Observable.js:157)
有什么想法嗎? 我無法理解為什么會發生這種情況...在“開發工具”網絡標簽中,它甚至沒有顯示網絡通話...
從錯誤消息看來,您只需要不讓undefined
傳遞到標題的.set(...)
中即可。
我這樣做:
getHeaders() {
const headers = new HttpHeaders();
headers
.set('Content-Type', 'application/json')
.set('Authorization', localStorage.getItem('token') || '');
return headers;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.