0
如何触发一个csv文件从一个按钮点击Angular内下载?Angular请求csv文件下载url,并强制下载
后端是php路由。
我尝试了一种解决方案,它动态地添加一个锚点标记,并附加到它的href属性,从http请求获取csv文件内容。但它不适用于我...还因为我们将csc内容附加到href属性,我担心它允许多少内容的href长度。
如何触发一个csv文件从一个按钮点击Angular内下载?Angular请求csv文件下载url,并强制下载
后端是php路由。
我尝试了一种解决方案,它动态地添加一个锚点标记,并附加到它的href属性,从http请求获取csv文件内容。但它不适用于我...还因为我们将csc内容附加到href属性,我担心它允许多少内容的href长度。
在摆弄现有的答案后,我尝试了下面的工作。
采用了棱角分明1.5.9
我做了它的工作就这样被window.location的设置CSV文件的下载网址。经过测试,并与最新版本的Chrome和IE11一起工作。
角
$scope.downloadStats = function downloadStats{
var csvFileRoute = '/stats/download';
$window.location = url;
}
HTML
<a target="_self" ng-click="downloadStats()"><i class="fa fa-download"></i> CSV</a>
在PHP设置了响应下面标头:
$headers = [
'content-type' => 'text/cvs',
'Content-Disposition' => 'attachment; filename="export.csv"',
'Cache-control' => 'private, must-revalidate, post-check=0, pre-check=0',
'Content-transfer-encoding' => 'binary',
'Expires' => '0',
'Pragma' => 'public',
];
'文本/ cvs'或'文本/ csv'? –