For starters: By default, angular expects the response as application/json
. You need to change it so you can parse it properly. For transferring files usually, it will be blob
.
Then you can use any library to convert and save this blob as a file. I prefer using 'file-saver`.
The code on angular side would look like :
this.http.get(url,{ observe: 'response', responseType: 'blob' }).subscribe(res => {
const blob = new Blob([res.body], { type: 'application/vnd.ms-excel' });
FileSaver.saveAs(blob, 'report.xls');
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…