title: Angular 11 wait until subscribe finishes getting data
body: <p>I have a auth.service and data.service. auth.service getting data from data.service but it checks before data arrives. So it returns undefined.</p>
  <p>auth.service getting data like this;</p>
  <pre><code>get isLoggedIn(): boolean {
    const user = JSON.parse(localStorage.getItem('user'));
    const emailVerify = this.dataservice.userStatService(user.uid);
    console.warn(emailVerify)
    return (user !== null &amp;&amp; emailVerify !== false &amp;&amp; emailVerify !== undefined ) ? true : false;
  }
  </code></pre>
  <p>data.service check user status function like this;</p>
  <pre><code>  userStatService(uid: any): any{
      console.error(uid)
      this.get(uid)
        .subscribe(
          data =&gt; {
            console.warn('status set', data.status)
            this.statData =  data.status;
          },
          error =&gt; {
            console.log(error);
      });
      return this.statData;
    }
  </code></pre>
  <p>and this code works like this now;
  <a href="https://i.stack.imgur.com/oulhQ.png" rel="nofollow noreferrer">See console logs</a></p>
  <p>I'm waiting for your code examples, thank you.</p>
  <p>Update:
  auth.guard code;</p>
  <pre><code>  canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable&lt;boolean&gt; | Promise&lt;boolean&gt; | boolean {
      if (this.authService.isLoggedIn() !== true) {
        this.router.navigate(['/auth/login'], { queryParams: { returnUrl: 'dashboard' } })
        .then(() =&gt; {
          this.authService.SignOut();
        });
      }else{
      return true;
      }
    }
  </code></pre>