【发布时间】:2015-09-07 11:03:37
【问题描述】:
我想在 angularjs 中单击按钮下载文件
<button ng-click=downloadfile()>download</button>
在控制器中
$scope.downloadfile=function()
{
//
}
请您解释一下我必须在下载文件函数中编写哪些功能
【问题讨论】:
标签: angularjs
我想在 angularjs 中单击按钮下载文件
<button ng-click=downloadfile()>download</button>
在控制器中
$scope.downloadfile=function()
{
//
}
请您解释一下我必须在下载文件函数中编写哪些功能
【问题讨论】:
标签: angularjs
在你的downloadFile() 函数中写出来。
//Initialize file format you want csv or xls
var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);
//this trick will generate a temp <a /> tag
var link = document.createElement("a");
link.href = uri;
//set the visibility hidden so it will not effect on your web-layout
link.style = "visibility:hidden";
link.download = fileName + ".csv"; //this is an example file to download, use yours
//this part will append the anchor tag and remove it after automatic click
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
【讨论】:
$scope.downloadFile = 函数(文档){
var token = $localStorage.authenticationToken || $sessionStorage.authenticationToken;
if (token) {
token = 'Bearer ' + token;
}
var url = new $window.URL($location.absUrl()).origin + "/api/voyages/" +
vm.voyage.id + '/documents/' + doc.id + '?auth=' + token;
$window.open(url);
};
【讨论】: