回答者 - https://stackoverflow.com/users/2064206/dcodesmith
$http({method: 'GET', url: '/someUrl'}).
success(function(data, status, headers, config) {
var anchor = angular.element('<a/>');
anchor.attr({
href: 'data:attachment/csv;charset=utf-8,' + encodeURI(data),
target: '_blank',
download: 'filename.csv'
})[0].click();
}).
error(function(data, status, headers, config) {
// if there's an error you should see it here
});
我使用Angular实现了从服务器下载文件到客户端的解决方案。在Google Chrome浏览器中,这是完美地工作的。但是这个解决方案在Mozilla Firefox浏览器中无法正常工作。
谢谢。