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

Top comments (1)

Collapse
 
anggachelsea profile image
Angga Lesmana

return postArray;