I have this odd problem where my query parameters of get requests do not work in a prod build, but they do work in a development build.
First I was using the HttpModule, I upgraded to HttpClientModule with hopes the problem might be solved. But unfortunately without success.
When switching to HttpClient I first came across this problem where nested objects were not passed properly. I fixed this by stringifying all nested objects.
Still, the problem remains where no query paramaters are passed when using a prod build.
This is the method that I am using to stringify the data before it is passed to HttpParams:
stringifyObjects() {
for (var prop in this) {
let isObject = typeof this[prop] === 'object' && this[prop] !== null
if(isObject) {
this[prop] = JSON.stringify(this[prop]) as any;
}
}
}
This is the code I am using to pass the params to the request
let params = new HttpParams({
fromObject: data
})
this.http.get(url, {params: params, headers: headers})
Also, I have tried to append every parameter separately:
let httpParams = new HttpParams();
Object.keys(data).forEach(function (key) {
httpParams = httpParams.append(key, data[key]);
});
return this.http.get(url, {params: httpParams, headers: headers})
All with the same result.
Anyone else who came across this issue, or anyone who knows what might be causing this?
Thanks in advance.
EDIT
I added this line to check where the problem starts.
console.log('params.toString()', params.toString());
Found out the this params.toString() returns an empty string (while with a development build, this returns the string correctly). My approach with this was to manually add the string to the url instead of passing is as params.
Still, I have not found a way to fix this or work around this.