programmatically appending query params to route if queryparam is used

Viewed 3540

I am prepared to spend the day researching this, but I hope you guys have answer as I think otherwise this would be an all day thing.

I have the following variables

  inputCity;
  inputGuestNumber;
  inputCapacitySelected;
  inputCuisineSelected;
  inputPrivacySelected;
  inputVenueTypeSelected;
  inputAmenitiesSelected;
  inputNeighborhoodSelected;

these variables may or may not be populated or defined depending on what information a user enters into a form.

I have the current router set up:

onSubmit(){
    this.router.navigate(['/venue-list',
    this.inputCity], {queryParams:{guestCount: this.inputGuestNumber, countOption: this.inputCapacitySelected,
    cuisineSelected:this.inputCuisineSelected, privacySelected:this.inputPrivacySelected,
      venueTypeSelected: this.inputVenueTypeSelected, amenitiesSelected: this.inputAmenitiesSelected,
    neighborhoodSelected: this.inputNeighborhoodSelected}

  });

I set it up this way hoping that if a queryparam was undefinded it would be ignored, instead all the queryparams are appended.

So now I am hoping to append the query params to the queryparams argument, if the query param is used. I have no idea how to do this and have started my research.

default values are not acceptable as it would still produce a gross url. Thank you all very much

2 Answers
Related