Angular Component
downlaodPDF(){
this.apiService.downlaodPDF(this.invoiceId)
.subscribe(
(data: Blob) => {
var file = new Blob([data], { type: 'application/pdf' })
var fileURL = URL.createObjectURL(file);
// if you downlaod
var a = document.createElement('a');
a.href = fileURL;
a.download = 'pdfFileName.pdf';
a.click();
},
(error) => {
console.log('getPDF error: ',error);
}
);
}
Angular Service:
downlaodPDF() {
// your get request URL
let url =`${environment.apiUrl}/api/invoice/download-app/667`
return this.http.get(url ,{responseType :'blob' as 'json'})
.pipe(map(data => {
return data;
}));
}
It really helped me a lot. Thank you so much