title: How to get an Observable for data from Firestore query in Angular 7?
body: <p>I have method in my service, inside which I am trying to return an Observable of the User object. Here is the my code - </p>
  
  <pre><code> constructor(private firestore: AngularFirestore,
      private db: AngularFireDatabase) { }
  
   /**
     * get user with given email, if not return null
     * 
     * @param email email to fetch
     */
    getUserByEmail(email: string): Observable&lt;User&gt; {
  
      var user: User;
  
      let userRef = this.firestore.collection("users").ref.where('email', '==', email);
  
      userRef.get().then(res =&gt; res.forEach(userDoc =&gt; {
  
        user = userDoc[0].data() as User; // since email IDs are unique, I want the 0th element.
        user.id = userDoc[0].id;
  
        console.log(user); // has the data
  
        // return user; // doesn't work, not the right thing
  
      }));
  
      console.log(user); // undefined, since call is async
  
      return of(user);
    }
  </code></pre>
  
  <p>Inside the component, I want that data for the next steps, so I did this - </p>
  
  <pre><code>checkEmail() {
  
      var user$: User
  
      this.us.getUserByEmail(this.existingUserForm.value.email).subscribe(user =&gt; {
  
        console.log(user);
  
        if (user) {
  
            this.msg$ = "success";
            // next steps
        }
        else {
          this.msg$ = "User with this email does not exist!";
        }
  
      });
  
    }
  </code></pre>
  
  <p>I am not sure how to return an observable from my service, so that I can use the data in my component. And is this the right way to do what I am trying to?</p>