Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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);
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading