Is there a way to set the file name for a blob in typescript? I have found a solution for IE, but it seems impossible for Chrome. I need something similar to this solution, but in 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);
}
}
This function is called from an HTML UI/Angular 2:
<button type="button" class="btn btn-success"
(click)="downloadFile('test')">Download <br /> Download </button>