this is the get method for (taken from http.d.ts
):
get<T>(url: string, options?: {
headers?: HttpHeaders | {
[header: string]: string | string[];
};
observe?: 'body';
params?: HttpParams | {
[param: string]: string | string[];
};
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
}): Observable<T>;
So you can do the following:
downloadFile(id): Observable<Blob> {
return this.http.get(this.baseUrl + `coursepurchased/receipt/` + bookingId, { responseType: "blob" });
}
and the component should look like:
getCourseReceipt(bookingId) {
this.studentInfoService.getCourseInvoice(bookingId).subscribe(
response => {
var fileName = 'test.pdf';
let blob:any = new Blob([response], { type: 'application/pdf; charset=utf-8' });
importedSaveAs(blob, fileName)
},
error => {
console.log(error);
this.alertService.showAlert(error.message, "error");
}
);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…