javascript – Angular 2 – the best way to handle many, different requests with custom query params


I have a list of products, I would like to filter that products e.g. by number, price, type etc. using checkboxes, selects and inputs. I get my data from REST API – using query params in GET method. My code is working but I’m wondering how to make it better and cleaner.

First, function in my component which connects with a service

  getMethod(): void {
    this.listService
      .getFilter(
        this.FullName,
        this.LastName,
        this.IP,
        this.price,
        this.age,
        this.dateTo,
        this.dateFrom,
        this.male,
        this.female,
        this.kid,
        this.group
      )
      .subscribe(
        (data) => {
          this.items = data;
        },
        (error) => (this.errorMsg = error)
      );
  }

Next, my service. First I check if all values have some content/set to true etc. Then I put all variables as params and at the end I delete empty variables.

  getFilterList(
    FullName: string,
    LastName: string,
    IP: number,
    Price: number,
    Age: number,
    DateTo: string,
    DateFrom: string,
    Male: boolean,
    Female: boolean,
    Kid: boolean,
    Group: boolean,

  ): Observable<ClientsAllData> {
   
    let isMale = '';
    if (Male=== true) {
      isMale= '0';
    }

    let isFemale= '';
    if (Female=== true) {
      isFemale = '0';
    }

    let isKid= '';
    if (Kid=== true) {
      isKid = '0';
    }

    {...}

    let params = new HttpParams()
      .set('FullName', FullName)
      .set('LastName', LastName)
      .set('IP', IP)
   

    {...}


    params = params.delete('FullName', '');
    params = params.delete('LastName', '');
    params = params.delete('IP', '');
    
    {...}

    return this.http.get<any>(
      MY_API,
      { params }
    );

Basically that code looks bad, this is my side learning angular project and I couldn’t find better way to do it. Could anyone show me how to write it cleaner or maybe better approach for that topic or just send some links, examples? What’s the best way to handle query params if there are many of them.