I am trying to encode ("application/x-www-form-urlencoded") an object in Angular using HttpParameterCodec. This object has a field as object which in turn has array of string. object structure as mentioned below.
export class SearchRequest {id: string = undefined;partnerIds: PartnerIds = undefined;}
export class PartnerIds { partnerId: string[] = undefined;}
Now when I am trying encode this object with utility code (which works fine with plain object) mentioned below, It is not in correct format due to list of string in it.
generateQueryParams(searchRequest) {
let httpParams: HttpParams = new HttpParams({encoder: new CustomEncoderComponent()});
Object.keys(searchRequest).forEach(key => {
httpParams = httpParams.append(key, searchRequest[key]);
});
return httpParams;
}
I tried with below query params format but it did not work.
1. id=123&partnerIds=XYZ&partnerIds=ABC
2. id=123&partnerId[]=XYZ&partnerId[]=ABC
3. id=123&partnerId=XYZ&partnerId=ABC
Please suggest How to pass this (SearchRequest) object within a query string in HttpClient?