I am currently facing an unusual issue in Angular and Ionic 2 related to a specific provider I have set up. Here is the code snippet:
getTransportations = function (category, maxResults) {
let url = `${this.domain}/wp-json/gf/v2/forms/1/entries?_labels=1&paging[page_size]=${maxResults}`;
if (category !== 'all') {
let search = {
field_filters: [{
key: '2',
operator: 'is',
value: category
}]
};
let url = `${this.domain}/wp-json/gf/v2/forms/1/entries?_labels=1&paging[page_size]=${maxResults}&search=${encodeURI(JSON.stringify(search))}`;
console.log(url);
}
let headers: Headers = new Headers();
headers.append("Authorization", "Basic " + this.bt);
headers.append("Content-type", "application/json");
return this.http.get(url, {
headers: headers
})
.map(response => response.json())
};
When the category is set to all
, everything works as expected. However, if the category is any other value, upon inspecting the Network tab in Chrome's Dev tools, I notice that the called URL does not include the search parameter. It only displays _labels
and paging
. Surprisingly, the console.log
statement inside the conditional block prints out the correct URL. Testing that URL in Postman retrieves the filtered results successfully.
Despite trying various methods of concatenating strings, I consistently face this issue.