【发布时间】:2017-09-19 21:08:11
【问题描述】:
我是 Angular 的初学者,这个问题可能很愚蠢或重复,很抱歉。
我的目标是只要 response.Done != true 就向 Web API 发送请求,这是我在 onInit 事件中从服务调用函数的代码:
export class FlightListComponent implements OnInit {
flightSearchResult: FlightSearchResult;
constructor(private service: FlightService) {
}
ngOnInit() {
let guid = Guid.newGuid();
this.service.getAll(guid).subscribe(response => {
if (response.Done != true) {
this.serveData(response);
// this.service.getAll(guid) ....
}
});
}
在每个请求中,我还获得了一些数据,我需要通过serveData() 将它们合并到一个主变量中。但是我认为应该有更好的方法来处理 observable 在这种情况下我需要调用 getAll() 几次,只要 Done 不等于 true 并且事件在最后给我所有数据而不在每个请求中合并。每个传递的 Observable 的所有值如何合并到一个 Observable 中。
有什么解决办法吗?
【问题讨论】:
标签: angular observable angular2-services