Help with RXJS


#1

Can anyone help me refactor this code so that I can call another function after ALL of the videoService get’s have finished?

this.teams.map((team:any) => {
        team.Assignments.map((a: Assignment) => {
          return this.videoService.getById(a.VideoId).subscribe(
            res => {
              let e = new Event();
              e.Id = a.Id;
              e.title = a.Name;
              e.location = '';
              e.message = a.Notes;
              e.startDate = a.StartDate;
              e.endDate = a.EndDate;
              e.video = res;
              e.team = team.Name;
              this.eventList.push(e);
            },
            err => {

          });
        })
      })

Thanks for any and all help!


#2

You want forkJoin.


#3

Thanks rapropos, I saw forkjoin but that looked like it’s for separate observables these nested observables depend on each other. If you could give me a short example of what you are thinking it would be much appreciated


#4

@rapropos I also wanted to show that in the subscribe method I am pulling data from the parent team and assignment, so I am not sure forkjoin allows that?