angular点击下载文件
程序员文章站
2022-04-10 13:59:29
...
home.component.html
<button type="button" (click)="download()">下載</button>
home.component.ts
downloadFile(data: any) {
var blob = new Blob([data], { type: 'text/csv' });
var url = window.URL.createObjectURL(blob);
window.open(url);
}
download() {
this.headers = new Headers({});
this.headers.append('Authorization', this.storageSvc.getUserToken());
let ActionUrl = 'xxxxxxxxxxxxxx';
this.http.get(ActionUrl , { headers: this.headers }).subscribe(data =>
this.downloadFile(data.text())),
error => console.log("Error downloading the file."),
() => console.info("OK");
}
上一篇: MySQL基础-存储过程
下一篇: SpringAOP在web应用中的使用
推荐阅读