title: How to get data from firestore DB in outside of onSnapshot
body: <p>Result undefined when I try to get value from firestore and put to a variable, but works in console.</p>
  
  <p>My code:</p>
  
  <pre><code>this.db.collection('Users').doc(uid).get()
    .then((docSnapshot) =&gt; {
      if (docSnapshot.exists) {
        this.db.collection('Users').doc(uid)
          .onSnapshot((doc) =&gt; {
            console.log(doc.data()); //working
            perfil = doc.data(); //not working
          });
      }
    });
  
  console.log(perfil); //not working. Display undefined
  </code></pre>