[英]Angular: Send more than two arguments in HTTP get request
我正在开发一个应用程序,我想在单击模板上的按钮后下载文件。 屏幕上显示了许多文件,每个文件都有一个单独的按钮。 我将数组的索引号发送到 Angular,我想将其作为参数发送到后端。 但是,我还想在我的 arguments 中添加 blob 的 responseType 并添加这两个 arguments 给我一个错误。 这是我的代码:
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 方法不能使用超过两个 arguments 会出错。 还有其他方法可以将其发送到后端吗?
get 方法接受两个 arguments:
在您的代码中,您将分别传递 params 和 responseType。 如果将它们组合成单个 object 就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.