How to download text/csv/pdf content as files from server in Angular

Rahul Kiwitech
Rahul K...
292 Points
26 Posts

I am trying to download pdf file that send from server and byte stream. I am using angularjs. How we can achieved using $http.

In service js:

this.downloadGuestPDF = function (eId, sBy, tTypeIds, bcode) {
var response = $http({
method: "get",
datatype: "data.json",
url: "/Download/GuestList",
params: {
EventId: eId,
sortBy: sBy,
ticketTypeIds: tTypeIds,
barcode: bcode,
format: 'pdf'
}
});
return response;
};

 

In Controller js:

var tmp = guestlistService.downloadGuestPDF(eventId, orderBy, '1', includeBarcode).then(function (response) {
$scope.TicketTypes = response.data;
});
Views: 9379
Total Answered: 1
Total Marked As Answer: 0
Posted On: 22-Dec-2016 02:06

Share:   fb twitter linkedin
Answers
Smith
Smith
2984 Points
80 Posts
         

You can use following code in controller as:

var anchor = angular.element('<a/>');
anchor.attr({
href: '/Download/GuestList?EventId=' + eventId + '&sortBy=' + orderBy + '&ticketTypeIds=' + ticketTypeInput + '&barcode=' + includeBarcode + '&qrcode=' + includeQRcode + '&format=pdf'
})[0].click();

 

Posted On: 11-Jan-2017 04:58
 Log In to Chat