I want to trigger a download once I receive certain data from the API. I do it the following way:
const anchor = window.angular.element('<a/>');
anchor.css({display: 'none'});
window.angular.element(document.body).append(anchor);
anchor.attr({
href: 'data:attachment/csv;charset=utf-8,' + encodeURI(data),
target: '_blank',
download: 'somedata.csv',
})[0].click();
anchor.remove();
This approach works both in Chrome and Firefox. However in Edge, for some reason, it doesn't.
Why doesn't it work in Edge and how can I fix it?