【发布时间】:2018-10-06 04:33:50
【问题描述】:
我正在尝试从角度 5 中的 url 下载 pdf 文件。通过将 url 和“下载”属性添加到“a”标签,它在 html 中运行良好。当我尝试在角度 5 中执行相同操作时,但是它不工作。
service.ts
pdfDownload() {
var options = new RequestOptions({responseType: ResponseContentType.Blob });
// Process the file downloaded
return this.http.get('https://.....test.pdf', options);
}
component.ts
this.rcycCommonService.pdfDownload().subscribe((res)=>{
this.saveFile(res.blob());
})
saveFile (blobContent) {
var blob = new Blob([blobContent], { type: 'application/pdf' });
saveAs(blob,"mypdf.pdf");
};
但它显示以下错误。
ERROR in src/app/rcyc-services/rcyc-common/rcyc-common.service.ts(426,137): error TS2345: Argument of type 'RequestOptions' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
Types of property 'headers' are incompatible.
Type 'Headers' is not assignable to type 'HttpHeaders | { [header: string]: string | string[]; }'.
Type 'Headers' is not assignable to type '{ [header: string]: string | string[]; }'.
Index signature is missing in type 'Headers'.
任何人都可以发布正确的代码以下载 angular 5 中的文件吗?
【问题讨论】:
-
到目前为止你尝试了什么?
-
我仍然无法从 url 创建 blob 对象
标签: angular5