I am having problem while using switchMap. What I am trying to do is:
1) Fetching first object/object's property from Firestore DB as an Observable
2) Using first Observable's property and make another Firestore call to get another Observable -which depends on first one- .
My question is, how can I pass first observable's result to second observable dynamically?
Any Help?
user.service:
this.userCollection = this.afs.collection('users',
ref => ref.orderBy("user_order", "desc").limit(1));
this.users$ = this.userCollection.valueChanges();
return this.users$
task.service:
getUserTask(users: User[]): Observable<UserTask[]> {
this.tasksCollection = this.afs.collection('user_tasks',
ref => ref.where("user_id", "==", users[0].user_id));
return
this.userTaskCollection.valueChanges();
}
myComponent.ts:
this.user$ = this.userService.getUser();
const userTaskResult = this.user$.pipe(
switchMap((user) => this.userTaskService.getUserTask(user))
);
userTaskResult.subscribe(x => console.log(x)); //returns nothing