【发布时间】:2018-08-25 22:20:42
【问题描述】:
您好,我正在使用 Angular 5。 我想要实现的是等到多个服务调用完成,我不知道我是否可以使用 forkJoin 运算符,因为服务调用取决于一个参数,例如:如果这个参数为 2,将会有两个调用这项服务。有没有办法让它以某种方式工作?
代码:
for (let i = 0; i < this._periodQtty; i++) {
this.service.getPastMonthData(i).subscribe(pastMonthData => {
if (pastMonthData && pastMonthData.length > 0) {
chartPoints = new Array<ChartPoint>();
pastMonthData.forEach(pastMonthElement => {
point = this.buildChartPoint(pastMonthElement, timeSpan);
if (point)
chartPoints.push(point);
});
chartDataSets.push({
data: chartPoints,
backgroundColor: "#f44336",
borderColor: "#ba000d",
pointHoverBorderColor: "#ba000d",
pointHoverBackgroundColor: "#ff7961",
pointRadius: 3.5,
label: "prueba 2",
fill: false,
type: 'line',
})
}
this._chartDataSets = chartDataSets;
this.ChartDatasetsUpdated.emit(this._chartDataSets);
})
}
【问题讨论】:
标签: angular rest typescript rxjs