How to search by parameters

Asked

Viewed 19 times

0

I am trying to do a search for parameters, where the user informs 3 parameters and searches this, follows as I am trying to do

FindByRdo(numero: number, ano: number, objeto: Objeto) {
    return find(this.http, `${this.endpoint}`);
  }

however, when passing to my dumb component, it gives me error, someone can tell me why?

  • Imagine that you would like to help someone, but only receive this information. What would be your suggestion?

1 answer

1

When I wish to make an appointment by query params, I use the following code.

  getMedicos(especialidade): Observable<Medico[]> {
    return this.http.get<Medico[]>(this.medicoUrl, {
       params: {
        'especialidade': especialidade
      }
    })
      .pipe(
        catchError(this.handleError<Medico[]>('getMedicos', []))
      )
  }

In my example I am consulting the endpoint:

private medicoUrl = 'http://localhost:8000/medicos/';

But the final endpoint running by the application will be:

http://localhost:8000/medicos/?especialidade=clinico

This way I imagine that in your case it would be something like 3 query params, soon in your example would be something like:

FindByRdo(numero: number, ano: number, objeto: Objeto) {
    return this.http.get(`${this.endpoint}`, {
                params: {
                         'numero':numero, 
                         'ano': ano,
                         'objeto':  o });
  }

Note that in my example I used the http method GET. It wasn’t clear which was the http method that used.

  • Sensational, thank you so much for your help and I apologize for providing little information

Browser other questions tagged

You are not signed in. Login or sign up in order to post.