0

I cannot figure out how can I solve the following problem.

There is an object type:

Box { 
    Fruit[n]: {
      Kinds[n]: {  
        id: string;
        name: string;
      }
    }
}

I got the box of fuits from an API call as an Observable (Angular2) [Fruit[]] then I want to populate its "navigation property" with another API call what gives back an observable as well like:

  Box.foreach(fruits =>
       fruits.foreach(f => 
           f.kinds.foreach(k => 
                k.name = kindservice.getKindName(k.id) // <- observer
    )))

How can I do it with RxJs?

I tried many ways, there are many mapper but I could not figure out yet. I used the Observable.from(..) as well but there was no luck.

Thank you

Lajos
  • 2,549
  • 6
  • 31
  • 38

1 Answers1

2

Your most inner loop has 2 problems:

  1. You assign an observer to a value.
  2. Your observer stays cold.

Try changing it to:

 Box.foreach(fruits =>
       fruits.foreach(f => 
           f.kinds.foreach(k => 
                kindservice.getKindName(k.id).subscribe(name => k.name = name)
    )))
Meir
  • 14,081
  • 4
  • 39
  • 47