Wednesday, 27 January 2016

angularjs http response a download


http://stackoverflow.com/questions/17177303/spring-download-response-as-a-file

Somebody said this is not possible, which is wrong, the solution is :

$http({method: 'GET', url: '/someUrl'}).
  success(function(data, status, headers, config) {
     var anchor = angular.element('<a/>');
     anchor.attr({
         href: 'data:attachment/csv;charset=utf-8,' + encodeURI(data),
         target: '_blank',
         download: 'filename.csv'
     })[0].click();

  }).
  error(function(data, status, headers, config) {
    // if there's an error you should see it here
  });


http://stackoverflow.com/questions/20904151/download-text-csv-content-as-files-from-server-in-angular


No comments:

Post a comment