Angular: 在 HTTP get 请求中发送两个以上的参数

Angular: Send more than two arguments in HTTP get request

我正在开发一个应用程序,我想在单击模板上的按钮后下载文件。屏幕上显示了许多文件,每个文件都有一个单独的按钮。我将数组的索引号发送到 Angular,我想将其作为参数发送到后端。但是,我还想在我的参数中添加一个 blob 的 responseType 并且添加这两个参数会给我一个错误。这是我的代码:

Angular

onDownloadFiles(i: any)
{
this.fileToDownload = i;
console.log(this.fileToDownload);

const params = new HttpParams().set('id3', this.fileToDownload);
this.http.get('http://localhost:3000/downloadfile', {params}, {responseType: "blob"}) //I want to add both these
.pipe(map(responseData => {
  return responseData;
}))
.subscribe(response => {

   this.downloadFile(response, ("application/msword" || "application/vnd.openxmlformats- 
   officedocument.wordprocessingml.document"));

})
}

downloadFile(data: any, type: string)
{
let blob = new Blob([data], {type: type});
let url = window.URL.createObjectURL(blob);
let pwa = window.open(url);

if(!pwa || pwa.closed || typeof pwa.closed == "undefined")
{
  alert("Please disable your pop up blocker and try again.");
}
}

http.get 方法不能接受两个以上的参数,这是一个错误。还有其他方法可以将其发送到后端吗?

get 方法接受两个参数:

  1. url
  2. options -- 由 headers、params、responseType 和其他字段组成。

在您的代码中,您分别传递了参数和响应类型。如果您将它们组合成一个有效的对象。