I am filtering an array of JSON objects, I want to return the found object based on the passed in id argument.
getClient(id) {
return this.http.get<any>(' http://localhost:3000/clients')
.pipe(
filter(client => client.idNumber === id)
);
}
The observer to the above is not triggered and does not receive any data.
getClient(id)
.subscribe(
(data) => {
// nothing here
}
)
The below implementation of getClient achieves what I want.
getClient(id) {
return this.http.get<any>(' http://localhost:3000/clients')
.pipe(
map(clients => clients.find(client => client.idNumber === id))
);
}
I would like to understand, am I using the filter operator the wrong way? And how is my usage different from the one here