0

I'm writing a code to search a list in angular, there I need to pass filtering options (form fields) to the API via GET call. this is working but, when there are multi select options (when passing an array within the GET call), there is a problem of doing it

Just think of country list in angular material select with multi option enabled

This is the format of parameters (if there is an error which I should follow in the GET call)

&country[]=LK,&country[]=UK&country[]=US

code is working for normal form fields without any issue, following is the code

   return new Promise((resolve, reject) => {
            let params = new HttpParams();
            let headers = new HttpHeaders({
                'Content-Type': 'application/json'
            });

            params = data;

            this._httpClient.get<any>(requestUrl, { headers, params })
                .toPromise()
                .then(
                    res => {

How I get the selected options as an array withing GET parameters

6
  • 1
    Ideally this should be done in POST. Is there any particular reason why you want to use GET? Commented Oct 26, 2019 at 12:26
  • Yes its because of the way API work. But I believe you are correct. Anyway thanks Commented Oct 27, 2019 at 5:58
  • Can you show what the API expect through a postman screenshot Commented Oct 27, 2019 at 6:23
  • I wish if I can. but I'm working under restricted env. Im not suppose to discuss the exact API calls or data due to NDA terms. Im extremely sorry. However this API is a GET call, say ------------------------------------------------ {{api_url}}/item/?shape[]=RD&shape[]=OT&color[]=F&price[lte]=260&price[gte]=12&price_type=P&package=S ------------------------------------------------------ Commented Oct 27, 2019 at 11:10
  • this returns the data with pagination links. so pagination links contains the page ids as well as above parameters . --------------------------------------------- "links": { "first": "URL/item/?shape%5B0%5D=RD&shape%5B1%5D=OT&color%5B0%5D=F&price%5Blte%5D=260&price%5Bgte%5D=12&price_type=P&package=S&page=1", "last": "URL/item?shape%5B0%5D=RD&shape%5B1%5D=OT&color%5B0%5D=F&price%5Blte%5D=260&price%5Bgte%5D=12&price_type=P&package=S&page=1", "prev": null, "next": null }, ---------------------------------------------- Commented Oct 27, 2019 at 11:10

0

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.