I am trying to subscribe to BehaviorSubject and then to an observable depends on a condition
the BehaviorSubject is :
orderListSubject= new BehaviorSubject<any>({orderListTouched: false, orderList: []});
myAllOrders = new BehaviorSubject<OrderModel[]>([])
I have a service that tries to check if orderListTouched is false, i need to subscribe to another observable to push values to the orderList
The function that will be called if orderListTouched is false :
getMyOrderList(){
this.courseService.getMyOrderList(this.user.uid).snapshotChanges().pipe(first())
}
here the function that i am trying to use to wrap this case :
listenToOrderList(){
this.courseService.orderListSubject.pipe(map(ev =>{
return ev.orderListTouched;
}), switchMap((res)=>{
if(res === false){
return this.getMyOrderList()
}if(res === true){
return this.myAllOrders
}
}
}))
}
when i am doing such way I am getting an error : Argument of type '(res: any) => void' is not assignable to parameter of type '(value: any, index: number) => ObservableInput'. Type 'void' is not assignable to type 'ObservableInput'.
please advise!
getMyOrderList()
doesn't return anything. Add areturn
statement. – mbojko