接下来是问题所在。我从服务中获得纯链接,点击此链接,用户可以直接从亚马逊s3存储桶下载任何文件。我不能使用ajax,因为它将是CROS域请求,所以我试图模拟点击动态链接。该功能正常,但下载没有开始。我的问题在哪里或我做错了什么?提前谢谢。
function triggerClick() {
$timeout(function() {
console.log($scope.theLink); // returns link
console.log(angular.element('#download')); // returns element
angular.element('#download').triggerHandler('click'); // returns nothing
}, 0);
};
$scope.download = function (obj) {
downloadServices.attachment(obj)
.then(function (response) {
$scope.theLink = response.url;
triggerClick()
})
}
HTML
<a id="download" ng-click="triggerClick(); $event.stopPropagation();" ng-href="{{theLink}}" ng-hide="true">
Download
</a>
html for download function
<div ng-repeat="att in attachments">
<div class="attach" ng-click="download(att)">
<span>{{att.displayFilename}}</span><br>
</div>
</div>
答案 0 :(得分:0)
这就是我解决这个问题的方法:
<div >
<div ng-repeat="att in attachments">
<div class="attach" ng-click="download(att)">
<span>{{att.displayFilename}}</span><br>
</div>
</div>
<a id="download" ng-href="{{theLink}}" ng-hide="true" download>
Download
</a>
</div>
HTML
{{1}}