Angular 角度:如何在for循环中使用服务?
如何在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 (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);})代码>