Recently, I developed an AngularJS program to facilitate file downloads from the server. Below is the code:
HTML Code
<a download="fullList.csv" ng-href="{{ fullListUrl }}" type="button" class="btn btn-success btn-xs exec-batch" ng-click="exportCSVBulk(batchExec)">
<span class="glyphicon glyphicon-ok"></span> EXPORT AS CSV
</a>
AngularJS Controller
$scope.exportCSVBulk=function(){
var page = "../importExportService/exportBulkCSV/"+batchExec.id;
$http.get(page).success(function(response) {
$scope.fullListUrl = 'data:text/csv;charset=utf-8,' + escape(response);
});
}
My current approach involves triggering the exportCSVBulk
function when a user clicks on the EXPORT AS CSV
link, setting the URL value (fullListUrl) in the process. However, due to the nature of this being an Ajax request, there seems to be a delay in redirection upon clicking the link. Is there a solution to this issue, or perhaps an alternative method that can be implemented?