altergothen
altergothen

Reputation: 495

Http rxjs - Passing Subscribe result to another function

Please would you kindly guide me in the right direction?

I am trying to pull records from an old Http REST service, restructure the data, then post it to firebase.

I'm not sure if this is the completely wrong approach or I misunderstand observable's completely. Your guidance will be most appreciated. How to send this new listing to another DataService function: exportToFirebase(new_listing) ?

onServiceCall() {
  this.httpDataService.getData().subscribe((itemData) => {
    this.itemDataJSON = itemData;
    if (this.itemDataJSON) {
      this.itemDataJSON.forEach(function(value) {
        let new_listing = new Listing(value.id, value.name, value.category);
        //console.log(new_listing);
        //How to send this new listing to another firebaseDataService function exportToFirebase(new_listing);
      });
    }
  });
}

Upvotes: 0

Views: 183

Answers (1)

kctang
kctang

Reputation: 11202

This demo does what you want, using mocked http & firebase services.

// --- make http call
httpCall.pipe(
  // --- construct an array of "new_listing" (of just one, up to u) and pass along the observable chain
  concatMap(httpNumbers => of(...httpNumbers)),
  // --- make the firebase call
  concatMap(number => firebaseCall(number))
).subscribe(val => console.log(val))

Hope this helps. If this does not make sense, then you need to read up on RxJS.

Upvotes: 1

Related Questions