UPDATE:
I've found a total working solution for this, and unlike the old answer, it works on FF and IE:
var blob = new Blob([response], {type: 'text/json'});
// FOR IE:
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob);
}
// For Other browsers (tested on Chrome, FF)
else{
var e = document.createEvent('MouseEvents'),
a = document.createElement('a');
a.download = filename;
a.href = window.URL.createObjectURL(blob);
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':');
e.initEvent('click', true, false, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
}
Old answer:
Thanks to topless for guiding me to a proper answer. Here's how I got it working:
myService.exportData().$promise.then(function (response) {
var anchor = angular.element('<a/>');
anchor.attr({
href: 'data:attachment/json,' + encodeURI(JSON.stringify(response)),
target: '_blank',
download: 'exported logs.log'
})[0].click();
})
Also, Now I dont need to set the headers at the API side.
res.send(myFileText)
works just fine!
NOTE: DOES NOT WORK IN IE & SAFARI