http.post不起作用的Angular reportProgress事件

时间:2017-07-24 14:06:27

标签: angular

是否可以将reportProgress与http.post一起使用? Angular在其HttpClient部分(https://angular.io/guide/http)中的http请求设置不同 我的服务提供商设置如下:

postForm(shortForm: any): Observable<ShortFormModel> {
 let headers = new Headers({'Content-Type': 'application/json'});
 let options = new RequestOptions({
  headers: headers
});

return this.http.post(this.preCheckUrl, shortForm, options)     
  .map((res) => this.extractData(res))
  .catch(
  (error: any): Promise<any>=> {
    console.error('An error occurred', error); 
    this.router.navigate(['/error', error]);
    return Promise.reject(error.message || error);
  }
)
}

private extractData(res: Response) {
  let body = res.json();     
  return body || { };
}

我尝试在选项中添加reportProgress: true,但收到错误:Argument of type '{ headers: Headers; reportProgress: boolean; }' is not assignable to parameter of type 'RequestOptionsArgs'. Object literal may only specify known properties, and 'reportProgress' does not exist in type 'RequestOptionsArgs'.

0 个答案:

没有答案