【发布时间】:2018-08-22 22:46:50
【问题描述】:
我想在 (angular 5) 中制作一个像这样的 observable。
如何在 Angular 6 中声明 responseType?
Angular 5 代码:
public ExportSomeThing(
ano: number
): Observable<IDownloadArquivo> {
let q = this.http
.get(this.apiUrl + ano + '/pordia/excel', {
responseType: ResponseContentType.Blob // <<<-- This code
}).map((res) => {
我的 Angular 6 代码:
public MyExport(
ano: number
): Observable<IXpto> {
let q = this.http
.get( this.api_rul + ano + '/some_path/', {
responseType: "ResponseContentType.Blob" // <<<--- error here !!!
}).map((res) => {
错误是:
[ts]
Argument of type '{ responseType: "ResponseContentType.Blob"; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
Types of property 'responseType' are incompatible.
Type '"ResponseContentType.Blob"' is not assignable to type '"json"'.
如何使我的 http.get 在 Angular 6 中相似?
我正在尝试下载Excel方法!
【问题讨论】:
-
显然枚举已被弃用,正如它在枚举描述中所说的那样。现在写
responseType: 'blob'就足够了。注意不要在 get/post 方法调用中使用泛型参数,因为现在返回类型很明显不需要泛型参数。任何来这里的人都可以看到:angular.io/guide/http#requesting-non-json-data
标签: angular angular5 angular6 httpclient response