When filtering products, I would like to send the array only if it contains elements. Is this possible?
Request function:
getRecipes(page, pageSize, filters){
let body = JSON.stringify({ "size": pageSize, "page": page, "listOfFilters": filters});
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post('http://localhost:8080/cookbook/recipe/filter',body,options)
.map((res: Response) => res.json());}
Filter Class:
export class Filter{
products = new Array<String>();
rating: {[key: string]:string} = {};
level: {[key: string]:string} = {};
}
The current JSON format is:
{"size":10,"page":1,"listOfFilters":{"products":[],"rating":{"from":"1","to":"5"},"level":{"from":"1"
,"to":"5"}}}
I would like it to be like this (when the products list is empty):
{"size":10,"page":1,"listOfFilters":{"rating":{"from":"1","to":"5"},"level":{"from":"1"
,"to":"5"}}}