Despite using the rxjs
filter
in my angular
project, I'm encountering difficulties in filtering records. Here is the function in question:
public getOrders(type: string, filterObj = {}, otherParams = {}): Observable<{ name: string; qt: number }[]> {
return this.http.get(apiUrl, { params: { filter: JSON.stringify(filterObj), ...otherParams},
})
.pipe(map((res: any) => res.payload))
.pipe(filter((order: any) => order.name && /\S/.test(order.name)));
}
The current implementation is not yielding the expected results. No values are being returned.
However, when I make the following adjustment, the code functions as intended:
public getOrders(type: string, filterObj = {}, otherParams = {}): Observable<{ name: string; qt: number }[]> {
return this.http.get(apiUrl, { params: { filter: JSON.stringify(filterObj), ...otherParams},
})
.pipe(map((res: any) => res.payload.filter((order: any) => order.name && /\S/.test(order.name))))
}
What could be causing the issue here?