Property 'blob' does not exist on type 'HttpResponse<any>'

304 views Asked by At

i am trying to upgrade angular 4 to 5 and for that i had to import HttpClient, HttpResponse , HttpHeaders from @angular/common/http instead of importing Http, Response, Headers, RequestOptions, ResponseContentType from '@angular/http';

but in my code earlier i was using let headers = new Headers(); which i replaced with let headers = new HttpHeaders(); and responseType: ResponseContentType.Blob replaced with responseType: 'blob'

now in method getData() res.blob() says Property 'blob' does not exist on type 'HttpResponse'.

ExcelDownload(_getRequestUrl: string) {
            let headers = new HttpHeaders();
            headers.append('Content-Type', 'application/json' ); 
            return this.http.get(this.getUrlWithEmpId(_getRequestUrl), {
                headers : headers,
                responseType: 'blob'
        }).map(response => this.getData(response)) .catch(error => this.handleError(error));
        }   
        public getData(res: HttpResponse<any>) {
            let headers = res.headers;
            let contentType = headers.get('Content-Type');
            var blob;
            try {
                if(contentType === 'pdf' || contentType === 'application/pdf') {
                    //chek this
                    blob = new Blob([res.blob()], { type: "application/pdf"});
                } else {
                    //check thi
                    blob = new Blob([res.blob()], { type: "application/vnd.ms-excel"});
                }
            }
            catch (e) {
              
            }
            return blob;
        }
0

There are 0 answers