“响应”类型中缺少Angular 7属性“大小”

时间:2018-11-29 13:16:18

标签: angular

所以最近我更新了我的角度应用程序,我尝试这样做。而这个错误弹出,我不知道如何解决。该错误在函数中弹出,该函数中应用程序下载Excel工作表并尝试在另一个窗口中打开它,此操作在更新之前有效。但是在我更新到angular 7.1.0之后,它给了我以下错误:

// the function related to this error is shown down below    
ERROR in src/app/adres.service.ts(87,28): error TS2322: Type 'Response' is not assignable to type 'BlobPart'.
      Type 'Response' is not assignable to type 'Blob'.
        Property 'size' is missing in type 'Response'

Adres服务的导入

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { HttpModule, ResponseContentType, Jsonp, RequestOptions, Headers } from '@angular/http';
import { Mail } from './models/mail';
import { Klant } from './models/klant';
import { Observable } from 'rxjs/Observable';
import { GlobalsService } from './globals.service';

功能

  private downloadFile(data: Response) {
    const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
    const url = window.URL.createObjectURL(blob);
    window.open(url);
  }

Package.json

 "dependencies": {
    "@angular/animations": "^7.1.1",
    "@angular/cdk": "^7.1.0",
    "@angular/common": "~7.1.0",
    "@angular/compiler": "~7.1.0",
    "@angular/core": "~7.1.0",
    "@angular/forms": "~7.1.0",
    "@angular/http": "^7.1.1",
    "@angular/material": "^7.1.0",
    "@angular/platform-browser": "~7.1.0",
    "@angular/platform-browser-dynamic": "~7.1.0",
    "@angular/router": "~7.1.0",
    "chart.js": "^2.7.3",
    "core-js": "^2.5.4",
    "ng2-ckeditor": "^1.2.2",
    "ng2-datepicker": "^3.1.1",
    "ng2-google-charts": "^3.5.0",
    "rxjs": "^6.3.3",
    "rxjs-compat": "^6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.11.0",
    "@angular/cli": "~7.1.0",
    "@angular/compiler-cli": "~7.1.0",
    "@angular/language-service": "~7.1.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.6"
  }

我当前正在使用的功能在7.1.0更新之前有效。谁能告诉我发生了什么以及如何在此版本中修复它?

2 个答案:

答案 0 :(得分:1)

我不确定原因为何或何时更改,但我确实知道如何解决。只需将Response更改为any,就像这样:

  private downloadFile(data: any) {
    const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
    const url = window.URL.createObjectURL(blob);
    window.open(url);
  }

您似乎以角度下载文件的方式发生了变化。由于存在angular的可爱any类型,所以我认为它可以解决问题,并且确实可以。

答案 1 :(得分:0)

private downloadFile(data: File) {
    const blob = new Blob([data], { type: 'text/csv' });
    // rest of the stuff
}

类型文件对我来说可以下载xlsx