简体   繁体   English

需要 Angular ESLint 错误参数键

[英]Angular ESLint Error Parameter key required

I am trying to download a file using below Angular Code but I keep on getting Parameter "key" required我正在尝试使用以下 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");
  });

It keeps on printing Alert :: label error Error: Parameter "key" required.它不断打印警报::标签错误错误:需要参数“key”。 Couldn't find anything relevant.找不到任何相关内容。 This error is being thrown by TranslateService but I couldn't figure out why这个错误是由 TranslateService 抛出的,但我不知道为什么

I found out the solution to the issue.我找到了问题的解决方案。 Default responseType is blob |默认 responseType 是 blob | undefined.不明确的。 Adding blob responseType in this.http.get() options parameter resolved the issue.在 this.http.get() 选项参数中添加 blob responseType 解决了该问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM