繁体   English   中英

如何在 Angular 中的 HTTP GET 请求中发送正文中的值?

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

我在我的服务中写了以下 function:

 /**
   * 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);
  }

我现在想在正文中发送 sendSelectedValues。 在帖子和补丁中很容易做到。 它是如何在 get 中工作的? 不幸的是,我还没有找到解决方案....你能帮帮我吗?

您可以使用 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 });
  }

你不能在体内这样做

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM