Observables are a stream and will execute and complete when they are done. Fair enough. In one component with multiple API calls using a service, can anything be done to ensure that one observable completes before another starts?
So in the below example, what can be done to make sure that getOptions completes before getReport is started. getReport relies on data being obtained by getOptions.
ngOnChanges() {
if (this.treeResult != null) {
for (var index = 0; index < this.treeResult.length; index++) {
var element = this.treeResult[index];
this.thumbnailView = null;
this.getOptions(element.id);
this.getReport(element.id, this.a, this.b, element.c);
}
}
}
getOptions(id: number) {
this._Service.GetOptions(id)
.subscribe(options => { this.select = options[0].Options1, this.num = options[0].Options1[0].optionId,
error => this.errorMessage = <any>error)
}
getReport(id: number, a: number, b: number, c: string) {
this._Service.GetReport(id, a, b, c)
.subscribe(data => { this.data = data }, error => this.errorMessage = <any>error);
}
Happy to supply more info if needed