且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular 2下载带有身份验证的.CSV文件点击事件

更新时间:2023-12-02 14:17:22

看起来你只需要解析响应的主体,即

Looks like you just need to parse the body of the response i.e

let parsedResponse = data.text();
this.downloadFile(parsedResponse);

我还建议您使用 FileSaver 即使在2016年下载文件也似乎没有一种标准的方式在浏览器中执行此操作。

Also I would recommend you use FileSaver to download files as even in 2016 there does not seem to be a standard way to do this across browsers.

let blob = new Blob([data], { type: 'text/csv' });
saveAs(blob, "data.txt");

如需更深入的指南,请检查这里

For a more in depth guide check here