joy*_*joy 8 download angularjs angular-resource
我正在使用Angular js来显示加载屏幕.它适用于除REST服务之外的所有REST服务调用以下载文件.我理解为什么它不起作用,因为下载我没有使用$ resource进行任何服务调用; 而不是我使用正常的方法下载文件因此Angular js代码没有任何控制启动/完成服务请求.我尝试使用$ resource来访问这个REST服务但是我从这个服务获取数据,在这种情况下,加载屏幕工作正常,但不确定如何使用此数据显示给用户以角度方式下载.以下是必需的细节.请帮忙.
方法1使用iframe方法:
/*Download file */
scope.downloadFile = function (fileId) {
//Show loading screen. (Somehow it is not working)
scope.loadingProjectFiles=true;
var fileDownloadURL = "/api/files/" + fileId + "/download";
downloadURL(fileDownloadURL);
//Hide loading screen
scope.loadingProjectFiles=false;
};
var $idown; // Keep it outside of the function, so it's initialized once.
var downloadURL = function (url) {
if ($idown) {
$idown.attr('src', url);
} else {
$idown = $('<iframe>', { id: 'idown', src: url }).hide().appendTo('body');
}
};
Run Code Online (Sandbox Code Playgroud)
方法2使用$ resource(不确定如何在屏幕上显示数据下载)
/*Download file */
scope.downloadFile = function (fileId) {
//Show loading screen (Here loading screen works).
scope.loadingProjectFiles=true;
//File download object
var fileDownloadObj = new DownloadFile();
//Make server call to create new File
fileDownloadObj.$get({ fileid: fileid }, function (response) {
//Q? How to use the response data to display on UI as download popup
//Hide loading screen
scope.loadingProjectFiles=false;
});
};
Run Code Online (Sandbox Code Playgroud)
以下是第二种方法的一些想法,您可以在下载完成后向用户提供一个链接:
| 归档时间: |
|
| 查看次数: |
6323 次 |
| 最近记录: |