I have a function that request data from an API using subscriptions. I am trying to re-write it so that it returns a boolean when all API calls have finished. Is there a better way to write this?
My current code:
public res1=null;
public res2=null;
getData(){
this.svc.getData1().subscribe(x={this.res1=x;})
this.svc.getData2().subscribe(x={this.res2=x;})
}
I was thinking of trying to create an Observable that listens for changes to the nested subscriptions: (not tested code!)
getData(): Observable<boolean>{
this.svc.getData1().subscribe(x=>{
this.res1=x;
this.svc.getData2().subscribe(x=>{this.res2=x;
return true;
})
})
)
}