我的service.ts中有以下方法,但是它总是抛出带有2-3个预期参数的错误,但是却得到了5.ts(2554),知道为什么吗?
deleteOneDoc(employeeuuid: String, docuuid: String, contentType: String, cloudinaryId: String) {
return this.http.put(environment.apiBaseUrl + '/deleteonedoc' + `/${employeeuuid}` + `/${docuuid}` + `/${contentType}` +
`/${cloudinaryId}`, employeeuuid, docuuid, contentType, cloudinaryId);
}
答案 0 :(得分:1)
HTTP PUT支持有限数量的参数。第一个是API端点的URL,第二个是请求正文(保存所有数据的对象),第三个是HTTP选项,其中包括标头和令牌。我将重构为这样的内容:
export class Document {
employeeId: string;
documentId: string;
contentType: string;
cloudinaryId: string;
}
deleteDocument(document: Document): Observable<boolean> {
const formData = new FormData();
const httpOptions = {
headers: this.headers
};
formData.append('employeeId', document.employeeId);
formData.append('documentId', document.documentId);
formData.append('contentType', document.contentType);
formData.append('cloudinaryId', document.cloudinaryId);
return this.httpClient.put<boolean>(environment.apiBaseUrl + '/deleteonedoc', formData, httpOptions);
}
P.S。确保导入所有依赖项,例如FormData
和Obeservable
。好的做法是定义API将返回的内容,这就是Observable<boolean>
的原因。我假设您返回一个布尔值以获取成功,但是您可以更改此值以返回所需的任何模型。
答案 1 :(得分:0)
这是因为http.put()
带有2-3个变量,但您要发送5个变量
environment.apiBaseUrl +'/ deleteonedoc'+ /${employeeuuid}
+ /${docuuid}
+ /${contentType}
+`/ $ {cloudinaryId}
employeeuuid
docuuid
contentType
cloudinaryId
您需要执行类似的操作,因为您已经在服务路径中发送了变量。您无需将它们添加到末尾
this.http.put(`${environment.apiBaseUrl}/deleteonedoc/${employeeuuid}/${docuuid}/${contentType}/${cloudinaryId}`, {observe: 'response'});