0
所以問題就在下一個。我從服務中獲得一個純粹的鏈接,通過點擊這個鏈接,用戶可以直接從amazon 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的下載功能
<div ng-repeat="att in attachments">
<div class="attach" ng-click="download(att)">
<span>{{att.displayFilename}}</span><br>
</div>
</div>
對不起..但你在哪裏調用download(obj)函數? –
你是否試過'.trigger('click');'而不是'triggerHandler'? – Ankh
@federicoscamuzzi看到我的更新回答 – antonyboom