I am currently facing an issue where I need to map an Object to HttpParams while excluding any parameter that is empty, null, or undefined.
export function mapToHttpParams(obj: object): HttpParams {
return Object.getOwnPropertyNames(obj)
.reduce((p, key) =>
p.set(key, (typeof obj[key] === 'undefined' || obj[key] === null) ? '' : obj[key]),
new HttpParams());
}
The above code still includes those empty parameters and I am looking for a solution like:
export function mapToHttpParams(obj: object): HttpParams {
return Object.getOwnPropertyNames(obj)
.remove(obj[key] === null && obj[key] === '' && obj[key] === null)
.reduce((p, key) =>
p.set(key, (typeof obj[key] === 'undefined' || obj[key] === null) ? '' : obj[key]),
new HttpParams());
}
I have been unable to find the correct way to achieve this - consistently encountering compilation errors.