我想下载文件,我是anguler的新手,所以我不知道该怎么办
<img src="assets/images/download.png" alt="IMG-LOGO" height="20" width="20" (click)="getfile(product.product_id)">
在ts文件中,我编写了用于api调用的函数
getfile(id){
this.filter.productid = id;
this.apiService.getfile(this.filter).subscribe((data: Array<object>) => {
this.fileUrl = data;
console.log(data);
});
}
答案 0 :(得分:1)
为什么需要利用angular来触发文件下载? HTML可以在没有任何帮助的情况下执行此操作...只需将代码更改为以下内容即可:
<a href="/path/to/file/{{ product.product_id }} ">
<img src="assets/images/download.png" alt="IMG-LOGO" height="20" width="20">
</a>
答案 1 :(得分:-1)
您的目标只是下载文件,而无需与Angular交涉。只需将其与a
标签链接即可。
<a href="/download/id" target="_blank">
<img src="assets/images/download.png" alt="IMG-LOGO" height="20" width="20">
</a>