【问题标题】:Angular ESLint Error Parameter key requiredAngular ESLint 错误参数键需要
【发布时间】:2020-12-26 17:38:52
【问题描述】:

我正在尝试使用以下 Angular 代码下载文件,但我不断收到 需要参数“key”

const headerValues = new HttpHeaders({ 'Content-Type': contentType!, 'Accept': contentType! });

this.http
  .get(`${this.resourceUrl}/${id}/download`, { headers: headerValues })
  .subscribe(data => {
    const blob = new Blob([data as BlobPart], { type: contentType });
    const downloadUrl = window.URL.createObjectURL(blob);
    window.open(downloadUrl);

    console.log('Alert :: Done ');

  }, (error) => {
    console.log('Alert :: error: ' + error);

  }, () => {
    console.log("this is the finally block");
  });

继续打印 Alert :: label error Error: 参数“key”需要。找不到任何相关内容。 TranslateService 抛出了这个错误,但我不知道为什么

【问题讨论】:

    标签: angularjs angular eslint


    【解决方案1】:

    我找到了问题的解决方案。默认响应类型为 blob |不明确的。在 this.http.get() options 参数中添加 blob responseType 解决了这个问题。

    this.http.get(`${this.resourceUrl}/${id}/download`, { headers, responseType: 'blob' }).subscribe((res) => {
            const file = new Blob([res as BlobPart], {
              type: contentType,
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-06
      • 2019-05-26
      • 1970-01-01
      • 2021-01-04
      • 2020-03-24
      • 2018-12-12
      • 2016-06-12
      • 1970-01-01
      相关资源
      最近更新 更多