I'm working on a combineLatest function that makes 2 http requests, but I only want the second request to be made if a specific condition is satisfied.
combineLatest([
this.leadsService.fetchALLLeadsActivityChart(this.clientId, this.getParams(optionsCurrent)),
this.leadsService.fetchALLLeadsActivityChart(this.clientId, this.getParams(optionsPrevious))]).pipe(takeUntil(this.chartSubscription)).subscribe(([current, previous]) => {
if(current.meta.success && previous.meta.success){
this.processGraphData({current: current.results, previous: previous.results});
}
});
Essentially, I need the second leadsService call to execute only when:
this.selectedDateFilter.enableComparisons = true;
Can this condition be incorporated into the combineLatest block? Or should it be handled as a separate call with the first request's result stored in a variable? Your input is greatly appreciated. Thank you!