Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度:如何在for循环中使用服务?_Angular_Loops_Angular Services - Fatal编程技术网

Angular 角度:如何在for循环中使用服务?

Angular 角度:如何在for循环中使用服务?,angular,loops,angular-services,Angular,Loops,Angular Services,如何在for循环中使用服务,并在所有循环执行服务后在代码中进一步使用服务?我的代码如下所示: for (let i = 0; i < this.calendarList.length; i++) { const curCalendarId = this.calendarList[i].id; this.cs.getAppointmentsWithinDay(curCalendarId, this.smallCalendarDate).subscribe(result => {

如何在for循环中使用服务,并在所有循环执行服务后在代码中进一步使用服务?我的代码如下所示:

for (let i = 0; i < this.calendarList.length; i++) {
  const curCalendarId = this.calendarList[i].id;
  this.cs.getAppointmentsWithinDay(curCalendarId, this.smallCalendarDate).subscribe(result => {
    for (let j = 0; j < result.length; j++) {
      this.calendarDisplay.appointments.push(result[j]);
    }
  });
}
this.getCalendarDisplay();
for(设i=0;i{
for(设j=0;j
当所有日历的所有约会都推送到阵列中时,我需要启动
getCalendarDisplay()
函数


提前感谢

您需要使用Observable forkJoin,请看以下示例:

var tasks=[];
tasks.push(Rx.Observable.timer(1000.first());
tasks.push(Rx.Observable.timer(1000.first());
tasks.push(Rx.Observable.timer(1000.first());
tasks.push(Rx.Observable.timer(1000.first());
log('等待所有任务完成…');
forkJoin(…tasks).subscribe(结果=>{console.log('done',results);})