我需要从我的后端下载一个 excel,它返回一个文件。
当我提出请求时,我收到错误:
TypeError:您在预期流的位置提供了“未定义”。您可以提供 Observable、Promise、Array 或 Iterable。
我的代码是:
this.http.get(`${environment.apiUrl}/...`)
.subscribe(response => this.downloadFile(response, "application/ms-excel"));
我试过 get 和 map(…) 但没有用。
细节: 角度5.2
参考:
import { HttpClient } from '@angular/common/http';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/finally';
import 'rxjs/add/operator/map'
import 'rxjs/add/operator/catch';
响应的内容类型:
Content-Type: application/ms-excel
怎么了?
原文由 Jean Carlos 发布,翻译遵循 CC BY-SA 4.0 许可协议
尝试这样的事情: