angularjs ajax无刷新下载

Posted BaldWinf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了angularjs ajax无刷新下载相关的知识,希望对你有一定的参考价值。

lb-statistics-filter-directive.html

 <a class="btn btn-sm btn-primary" ng-click="downloadExcel(downloadUrl)" target="_blank" ng-class="'disabledEvent':!hasPreviewData">

lb-statistics-filter-directive.js

  controller: function($scope,$http, $element, $attrs)
            $scope.downloadExcel = function(downloadUrl)
                console.log(downloadUrl)
                $http.get(downloadUrl,
                    responseType: "arraybuffer",
                    timeout:600000
                )
                .success(function (data, status, headers, config) 
                    var blob = new Blob([data], type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                    var a = document.createElement("a");
                    document.body.appendChild(a)
                    a.download =  $filter('date')(new Date(), 'yyyyMMddHHmmss') + ".xls";
                    a.href = URL.createObjectURL(blob);
                    a.click();
                )
            

以上是关于angularjs ajax无刷新下载的主要内容,如果未能解决你的问题,请参考以下文章

angularJS实现无刷新文件下载

ajax的无刷新文件下载

Ajax实现无刷新分页

Ajax省市区无刷新单表联动查询

走进AngularJs ng的路由机制

走进AngularJs ng的路由机制