Angular HttpClient ResponseTyp Error

2019-06-21 05:15发布

I try to download an image(png) from a api. My problem is, that for some reason only json files are accepted by ionic/angular.

return this.http.get(this.authKeys.serverURL, {headers: this.header, responseType: ResponseContentType.Blob});

Following error occurs:

 Argument of type '{ headers: any; responseType: ResponseContentType.Blob; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.   Types of property 'responseType' are incompatible.     Type 'ResponseContentType.Blob' is not assignable to type '"json"'.

For some reason only a response of type json is allowed...

1条回答
唯我独甜
2楼-- · 2019-06-21 05:24

responseType holds string value. So you should be passing either of these values

'arraybuffer' | 'blob' | 'json' | 'text';

In earlier version Angular 2, it API was designed to expect enum value for responseType, check here

查看更多
登录 后发表回答