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.

2
  • Try to specify the property: { responseType: 'json', params: params } Commented Jun 15, 2020 at 20:26
  • {params} is a ES6 shortcut for {params: params} Commented Jun 16, 2020 at 5:19

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

7 Comments

what' different?
params: apiParams
oh right. syntax error. he just forgot to add ': params'
Yup. Please do accept the answer if it helped solve the issue.
This symtax is correct {params} as it is a ES6 shortcut for {params: params}
|
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.