如何在typescript中为blob设置文件名?对于IE浏览器,我可以轻松设置文件名,但是对于Chrome浏览器似乎不可能。基本上,我需要类似于这个解决方案,但是使用typescript。
downloadFile(data: any) {
var blob = new Blob([data], {type: 'text/csv'});
let fileName = 'my-test.csv';
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
//save file for IE
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {
//save for other browsers: Chrome, Firefox
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
}
}
这个函数是从HTML UI / Angular 2调用的:
<button type="button" class="btn btn-success"
(click)="downloadFile('test')">Download <br /> Download </button>