获取角度为4的二进制数据(xls,pdfs,csvs)

时间:2017-10-22 15:34:33

标签: angular

我正在尝试应用此解决方案:How to download excel/Zip files in Angular 4 但我有一些错误。

我服务的代码是:

    return this.http.post(endpoint, 
                          body, 
                         {headers: new HttpHeaders({'Accept':'application/vnd.ms-excel'}) , 
                          responseType: ResponseContentType.Blob})
                     .map(res => res.blob());

但是我收到了这个错误:

Argument of type '{ headers: HttpHeaders; responseType: ResponseContentType.Blob; }' is not assignable to parameter of type '{ headers?: HttpHeaders; observe?: "body"; params?: HttpParams; reportProgress?: boolean; respons...'.

Types of property 'responseType' are incompatible.
Type 'ResponseContentType.Blob' is not assignable to type '"json"'.

我不知道该怎么做:\

1 个答案:

答案 0 :(得分:1)

制作responseType:" blob"解决了我的问题!

return this.http.post(endpoint, body, {responseType: "blob"}).map(res => res).catch(this.handleError);