Download the zip file and run the "save file" dialog from the angular method

I have a standard angular code that runs when a button is clicked:

$scope.downloadAll = function () {   
  $http.get("download.php?id=" + $scope.id).success(function (data) {
    }).error(function () {
        $scope.status = "Error: can not download table data from server.";
    }); 
 }

but my php script returns a zip archive, and its contents thus ends with a javascript variable, data strong>. I would like to change the behavior so that the zip archive is offered by the browser for storage on the local disk. How did I achieve this while retaining the angular button handler?

+1
source share
1 answer

In your angular controller, enter $windowand use it like this:

$scope.downloadAll = function () {
  $window.location.href = "/download.php?id=" + $scope.id;
}

, zip http, (content-disposition, mime type,...).

0

All Articles