0

I am trying to get data from search API. The search value is passed as a query string.

No errors at compile time, no errors at runtime.

const params = new HttpParams().set('search', 'pizza');
this.http
    .get('/hello', { responseType: 'json', params })
    .subscribe(console.log, console.log);

Generates the /hello GET query but without the query string parameters.

What's wrong?

Angular exact version is 9.1.11

EDIT

The issue does not come from Angular but on how I try to embed the app. It works when using the default dev server without trying to embed it.

Piyush Jain
  • 1,895
  • 3
  • 19
  • 40
AirGoatOne
  • 61
  • 1
  • 4

2 Answers2

1

I guess you need to specify which option to assign params to.

Try this:

const apiParams = new HttpParams().set('search', 'pizza');
this.http
    .get('/hello', { responseType: 'json', params: apiParams })
    .subscribe(console.log, console.log);
Manish
  • 6,106
  • 19
  • 64
  • 90
0

There is no issue with Angular or the syntax I am using. The issue came from the integration I tried to do. I tried to embed the Angular App in a web page and develop from there.

It doesn't seem to be a good idea.

Everything work with the default dev server.

AirGoatOne
  • 61
  • 1
  • 4