预期2-3个论点,但得到5.ts(2554)

问题描述 投票:-4回答:2

我在我的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);
  }
angular
2个回答
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);
}

附:确保导入所有依赖项,如FormDataObeservable。优秀的做法是定义API将返回的原因,这就是Observable<boolean>的原因。我假设你为成功返回一个布尔值,但是你可以改变它以返回你想要的任何模型。


0
投票

这是因为http.put()需要2-3个变量,但你发送它5

  1. environment.apiBaseUrl +'/ deleteonedoc'+ /${employeeuuid} + /${docuuid} + /${contentType} +`/ $ {cloudinaryId} employeeuuid docuuid contentType cloudinaryId

您需要执行类似的操作,因为您已经在服务路径中发送变量。你不需要将它们添加到最后

this.http.put(`${environment.apiBaseUrl}/deleteonedoc/${employeeuuid}/${docuuid}/${contentType}/${cloudinaryId}`, {observe: 'response'});
© www.soinside.com 2019 - 2024. All rights reserved.