2

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
ilgaz
  • 61
  • 3
  • What's returning `undefined`? Are you sure it's not because your formating where you have `return` and then `this.userTaskCollection.valueChanges();` on different lines? – martin Aug 16 '18 at 12:10
  • sorry, can not understand what you're point to? actually my question is, how can I pass first observable's result to second observable dynamically. – ilgaz Aug 16 '18 at 12:17

0 Answers0