Answer the question
In order to leave comments, you need to log in
Why is the http request being built incorrectly?
There is a method to send a request:
getStrongAlcoholReports(selectedItems?): Observable<ReportModel> {
let selecteditemstest = [];
let apiParams;
if (selectedItems) {
for (let code of selectedItems) {
for (let codesarr of code.codes) {
selecteditemstest.push(codesarr);
apiParams = selecteditemstest.join('&codes=');
}
}
return this.http.get<ReportModel>(this.listOfStrongAlcoholReports, { params: { codes: apiParams } });
} else {
return this.http.get<ReportModel>(this.listOfStrongAlcoholReports, { params: { codes: '200&codes=262' } });
}
}
Answer the question
In order to leave comments, you need to log in
Well, something like this
const params = codes.reduce(
(acc, code) => acc.append('codes', `${code}`),
new HttpParams(),
);
this.http.get<ReportModel>(this.listOfStrongAlcoholReports, { params });
codes
it is [200, 262 ]
HttpParams
const params = new HttpParams({
fromObject: { codes: codes.map(String) }
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question