在Angular中,是否可以通过NG-CLICK或NG-SUBMIT从服务器下载文件?(使用PHP)


Is it possible in Angular to do an NG-CLICK or NG-SUBMIT to download a file from a server? (Using PHP)

现在,我的函数是这样的

    scope.downloadCsv = function(){
         $http.({
          method:'POST',
          url:'php/crud.php',
          data:scope.postPayload,
          headers:{'content-type':'application/x-www-form-urlencoded'} 
          }).success(function(){console.log("download done!")});
     };

我尝试将该按钮绑定到ng-click, ng-submit,并按照Angular中从服务器下载文本/csv内容作为文件的说明(这可以工作,但在Firefox上不行)。

我不知道技术术语,但我假设我在某种程度上需要能够点击一个链接与"POST"请求,这样浏览器认为它不是一个ASYNC调用,我只是不知道如何完成它。它必须是post,因为我要将一堆数据传递给服务器,以便对其进行操作以生成CSV。任何帮助是非常感激!

不能使用ajax下载文件。我的第一选择是创建一个普通的html表单,发布到一个隐藏的iframe:

<form method="post" action="php/crud.php" target="hidden_iframe">
<input type="hidden" name="data" value="{{postPayload}}">
<button type="submit">Download!</button>
</form>
<iframe name="hidden_iframe"></iframe>