mercredi 24 octobre 2018

Downloading Excel File To Angular 4 From Laravel Using HttpClient

I'm trying to get download the excel file as soon as i click the button "onGetExcel()" but it shows "Unknown Error". I've tried to change the headers to application/excel but it still doesn't work. But while i try to copy the api to the browser, it suddenly downloads the excel file.

TS

onGetExcel() {
        this.reportsService.exportToExcel()
          .takeUntil(this.ngUnsubscribe)
          .subscribe(
            (data: any) => {
              console.log(data);
            },
            error => {
              alert('Error');
              console.log(error);
            });
      }

service.ts

exportToExcel() {
    let headers = new HttpHeaders();
    headers = headers.set('Accept', 'application/excel');
    return this.httpClient.get(this.url  + '/exports', {headers: headers, responseType : 'blob'})
    .map((response => response));
  }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire