You can use the RxJs Conditional Operator iff
to achieve that if both of your services return an Observable or a Promise.
The iff
operator takes 3 arguments, first when being your condition, 2nd and 3rd being your different services that return an Observable/Promise.
If the condition is true
subscribe to the first observable
, if it is false
subscribe to the second observable
iif(
() => {
//Add your condition here
return a + b === 4;
},
this.someService.someMethodWhenTrue(),
this.someService.someMethodWhenFalse()
)
.pipe(takeUntil(this.unsubscribe$))
.subscribe((items)=> {
this.someData = items;
});
I recommend you to read this https://www.learnrxjs.io/learn-rxjs/operators/conditional/iif