Try with something like this...
First of all, you will need file-saver node package so run
npm install --save file-saver
.
Then, try with something like this, I copy-paste my code that I used for something similar
public downloadPDF(): any {
var mediaType = 'application/pdf';
this.http.post(this.myUrl, {location: "report.pdf"}, { responseType: 'blob' }).subscribe(
(response) => {
var blob = new Blob([response], { type: mediaType });
saveAs(blob, 'report.pdf');
},
e => { throwError(e); }
);
}
This worked for me, but it was just for saving the file.
Let me know if it works!
UPDATE - ANGULAR7 & FILESAVER V.^2.0.1+
I've just migrated my app from Angular v.6 and Filesaver v.<2.0.1 (don't know what version it was but it was a previous one of 2.0.1).
In this new version, you'll have to change the import from:
import { saveAs } from 'file-saver/FileSaver';
to
import { saveAs } from 'file-saver';
Everything else works like previous version!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…