'Add find inside pipe
I have the following code :
await this.panelService.getActivePanels().subscribe(activePanels => {
panel = activePanels.find(panel => panel.serviceId === serviceId);
});
I want to add a pipe before the subscribe, that does the find operation, so when I subscribe I will get just the one panel returned by the find, is that possible? and how would it look?
Solution 1:[1]
What you are looking for is called map and you can use it like this:
this.panelService.getActivePanels().pipe(
map(activePanels => activePanels.find(panel => panel.serviceId === serviceId))
).subscribe(panel => {
console.log(panel);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Octavian Mărculescu |
