I have two methods that return observables. If first returns some data then no need to call the second method. But if the first method returns null then only call the second method.
getdefaultAddress(id) : Observable<Address[]> {
return this.http.get<Address[]>(this.url + 'users/' + id + '/addresses' + '?filter[where][default]=true')
}
getFirstAddress(id): Observable<any>{
return this.http.get<any>(this.url + 'users/' + id +'/addresses?filter[limit]=1' )
}
I can easily do this after subscribing to the first observable using if-else. Like
this.getdefaultAddress(id).subscibe(data =>{
if(data) {
// do something
}
else {
this.getFirstAddress(id).subscibe(data =>{
// do something
})
}
})
Now how can I check this without really subscribing to first observable? Any rxjs operator?
Thank you in advance