【发布时间】:2016-07-09 07:04:51
【问题描述】:
我需要执行一个函数,该函数处理由一系列可观察订阅产生的数据,但仅在它完成创建我的对象之后。
这是我的链子:
getFilters() {
this.filterSvc.getCamps()
.subscribe(
c => {
this.filters = c;
for (let camp of this.filters) {
this.filterSvc.getBuildings(camp.id)
.subscribe(
b => {
camp.buildings = b;
for (let building of camp.buildings) {
this.filterSvc.getFloors(building.id)
.subscribe(f => {
building.floors = f
});
};
});
}
});
// ONLY DO THIS AFTER THE OBJECT IS HYDRATED
this.globals.setCampFilters(this.filters);
}
如您所见,我需要从 getCamps 返回的每个项目创建一个订阅,并从每个结果中创建一个订阅,等等......然后说完,我想执行
setCampFilters(this.filters);
我如何才能等到我的所有营地都有建筑物并且所有这些建筑物都有楼层之后才去填充我的过滤器?
【问题讨论】:
标签: angularjs typescript angular promise observable