DEV Community

Cover image for Angular transforming data use rxjs operators
Angga Lesmana
Angga Lesmana

Posted on

Angular transforming data use rxjs operators

There are several cases that I am currently experiencing, namely, How to get response data from firebase whose response is in the form of an object like this

Image description

Honestly it's a bit difficult to display the data as follows, and try to transform that response use RXJS operators

this is exmple code for display data or transforming data

///write method to get that data
fetchData(){
this.nameService.namemethodfromService().pipe(map((items: any) => {
  const arrayData = [];
  for(const key of items){
 if(items.hasOwnProperty){
   postArray.push({...items[key], id: key})
 }
  }
return arrayData
})).subscribe((value: any) => {
      console.log(value);
this.dataItems = value
    })
}

Enter fullscreen mode Exit fullscreen mode

Image description

the rxjs I used is, map from rxjs/operators, pipe from rxjs

please sahre if there the other ways

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (1)

Collapse
 
anggachelsea profile image
Angga Lesmana

return postArray;

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay