Angular 应为2-3个参数,但得到5.ts(2554)
在我的service.ts中我有以下方法,但是它总是抛出错误,期望有2-3个参数,但是得到了5.ts(2554),知道为什么吗Angular 应为2-3个参数,但得到5.ts(2554),angular,Angular,在我的service.ts中我有以下方法,但是它总是抛出错误,期望有2-3个参数,但是得到了5.ts(2554),知道为什么吗 deleteOneDoc(employeeuuid: String, docuuid: String, contentType: String, cloudinaryId: String) { return this.http.put(environment.apiBaseUrl + '/deleteonedoc' + `/${employeeuuid}` +
deleteOneDoc(employeeuuid: String, docuuid: String, contentType: String, cloudinaryId: String) {
return this.http.put(environment.apiBaseUrl + '/deleteonedoc' + `/${employeeuuid}` + `/${docuuid}` + `/${contentType}` +
`/${cloudinaryId}`, employeeuuid, docuuid, contentType, cloudinaryId);
}
这是因为
http.put()
接受2-3个变量,但您发送的是5个变量
/${employeeuuid}
+/${docuuid}
+/${contentType}
+`/${cloudinaryId}
employeeuuid
docuuid
contentType
cloudinaryId
this.http.put(`${environment.apiBaseUrl}/deleteonedoc/${employeeuuid}/${docuuid}/${contentType}/${cloudinaryId}`, {observe: 'response'});
HTTP PUT支持有限数量的参数。第一个是API端点的URL,第二个是请求主体(保存所有数据的对象),第三个是HTTP选项,其中包括头和令牌。我会重构成这样:
导出类文档{
employeeId:字符串;
documentId:字符串;
contentType:字符串;
cloudinaryId:string;
}
deleteDocument(文档:文档):可观察{
const formData=new formData();
常量httpOptions={
headers:this.headers
};
formData.append('employeeId',document.employeeId);
formData.append('documentId',document.documentId);
formData.append('contentType',document.contentType);
formData.append('cloudinaryId',document.cloudinaryId);
返回此.httpClient.put(environment.apiBaseUrl+'/deleteonedoc',formData,httpOptions);
}
注意:确保导入所有依赖项,如
FormData
和Obeservable
。定义API将返回的内容是一种好的做法,这就是为什么可观察的原因。我假设您返回一个布尔值以获得成功,但您可以将其更改为返回您想要的任何模型。为什么同时使用字符串模板和字符串连接?http.put
需要2-3个参数,而您正在传递5个参数,假设您想通过url并在对象中传递这些变量到后端(想想req.params&req.body)您需要执行http.put(,{employeeuuid,docuuid,contentType,cloudinaryId})