1

I'm working on a simple get with search parameters, trying to use Angular's httpclient with HttpParams

  getOptions(id1: string, id2: string): Promise<string[]> {
return new Promise<string[]>((resolve, reject) => {
  var params: HttpParams = new HttpParams();
  params.set('id1', id1;
  params.set('id2', id2);
  this.httpClient.get<string[]>(`${this.appConfig.apiUrl}/api/task/getoptions`, {params: params}).subscribe(resp => {
    resolve(resp);
  }, error => {
    reject(error);
  })
});
}

My endpoint looks like that:

    [HttpGet("[action]")]
    public async Task<List<string>> GetOptions([FromQuery] string id1, [FromHeader] string id2)
    {
        //...do something
    }

I tried all attributes like [FromQuery], [FromForm], [FromHeader],... but the data I send never arrives to the controller, although method/endpoint is being called. The values are just null.

What am I doing wrong, or what am I missing?

Stefan R.
  • 438
  • 1
  • 5
  • 22

1 Answers1

1

and finally I found that the solution is on stackoverflow already...

Angular HttpClient params with method GET do not work

Stefan R.
  • 438
  • 1
  • 5
  • 22