fir*_*baa 6 javascript rest google-chrome angular angular-httpclient
在我的Angular6应用程序下,我使用HttpClient和一些标头注入到我的 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});
}
}
Run Code Online (Sandbox Code Playgroud)
我订阅的组件:
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);
});
}
Run Code Online (Sandbox Code Playgroud)
在 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)
Run Code Online (Sandbox Code Playgroud)
此错误仅出现在Chrome和IE11 中- 而在Firefox下,请求变得良好,但我没有得到它
任何想法,建议?
| 归档时间: |
|
| 查看次数: |
6413 次 |
| 最近记录: |