How can I send values in the body in the HTTP GET request in Angular?

Viewed 21

I have written the following function in my service:

 /**
   * Get all data
   * @param sendSelectedValues string
   */
  getAllActPlanBalanceYearData(sendSelectedValues: any): Observable<any> {
    const url = `/yearlyvalues/act-and-plan-balance`;
    return this.http.get<any>(`${environment.baseUrl}` + url);
  }

I would like to send sendSelectedValues in the body now. In the post and patch is easily doable. How does it work in the get? Unfortunately I haven't found a solution yet.... Can you help me?

1 Answers

you can do this with a queryParam:

 getAllActPlanBalanceYearData(sendSelectedValues: string): Observable<any> {
    const params = new HttpParams()
      .set('values', sendSelectedValues);
    const url = `/yearlyvalues/act-and-plan-balance`;
    return this.http.get<any>(`${environment.baseUrl}` + url, { params });
  }

you can't do that in the body

Related