我希望在(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 方法调用使用通用参数,因为现在返回类型是明确的,无需通用参数。任何来到这里的人都可以查看:https://angular.io/guide/http#requesting-non-json-data - mkb