簡體   English   中英

獲取請求“沒有重載匹配此調用”Angular HttpClient

[英]get request "No overload matches this call" Angular HttpClient

我的后端有一個 GET 方法,我將請求正文作為輸入發送並獲取結果列表作為返回。

現在在我的前端我有:

  search(cat: Cat): Observable<Cat[]> {
    return this.httpClient.get<Cat[]>(this.messageBaseUri+'/search', cat);
  }

我得到的錯誤是在 VsCode 中:

    (parameter) cat: Cat
No overload matches this call.
  Overload 1 of 15, '(url: string, options: { headers?: HttpHeaders | { [header: string]: string | string[]; }; observe: "events"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }): Observable<...>', gave the following error.
    Argument of type 'Cat' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe: "events"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
      Property 'observe' is missing in type 'Cat' but required in type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe: "events"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
  Overload 2 of 15, '(url: string, options: { headers?: HttpHeaders | { [header: string]: string | string[]; }; observe: "response"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }): Observable<...>', gave the following error.
    Argument of type 'Cat' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe: "response"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
      Property 'observe' is missing in type 'Cat' but required in type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe: "response"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
  Overload 3 of 15, '(url: string, options?: { headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }): Observable<...>', gave the following error.
    Type 'Cat' has no properties in common with type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.ts(2769)
http.d.ts(939, 9): 'observe' is declared here.
http.d.ts(1049, 9): 'observe' is declared here.
Peek Problem
No quick fixes available

我在這里讀到https://github.com/github/fetch/issues/635 GET 請求不能將正文作為輸入參數,但是我如何能夠通過示例郵遞員發送請求正文並在沒有錯誤?

get 沒有正文。 您可以傳遞 url 和選項來獲取請求。

您可以在以下鏈接中看到 get 的各種重載https://angular.io/api/common/http/HttpClient#get

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM