类型“ HttpResponse <any>”上不存在属性“ blob”

时间:2020-10-06 23:48:55

标签: angular5

我正在尝试将angular 4升级到5,为此我不得不从@ angular / common / http导入HttpClient,HttpResponse和HttpHeaders,而不是从'@ angular / http'导入Http,Response,Headers,RequestOptions,ResponseContentType。 ;

但是在我之前的代码中,我使用的是let headers = new Headers();我用let headers = new HttpHeaders()替换了它;和responseType:ResponseContentType.Blob替换为responseType:'blob'

现在在方法getData()res.blob()中说,类型'HttpResponse'上不存在属性'blob'。

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 个答案:

没有答案