title: angular 2 - routing guard returning observable<boolean>, understanding
body: <p>I guess this might more of a rxjs understanding topic but the context illustrates my want of it the best :)</p>
  
  <p>So below it the working code inside my PageGuard class, which prevents routing to pages unless a valid jwt exists in localStorage. </p>
  
  <p>CheckForToken() just appends Authorization Header if token exists in localStorage.</p>
  
  <pre><code>public isAuthenticated():Observable&lt;boolean&gt;{
      this.checkForToken();
      let isAuth = new Observable&lt;boolean&gt;(observer =&gt; {
          this.http.get(`https://testhan-api.selfbits.io/api/v1/user`,{headers: this.headers}).subscribe(res =&gt; {
              if (res.status === 200){
                  observer.next(true);
                  observer.complete();
              }else{
                  observer.next(false);
                  observer.complete()
              }
          },err =&gt; console.log(err));
      });
      return isAuth
  }
  
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable&lt;boolean&gt; {
      return this.isAuthenticated()
  }
  </code></pre>
  
  <p>and the routing path looks like this</p>
  
  <pre><code>{ 
      path:'dashboard', 
      component:DashboardComponent, 
      canActivate:PageGuard
  }
  </code></pre>
  
  <p>My question: So far, my understanding is that you need to subscribe to an observable, in order to execute it, like</p>
  
  <blockquote>
    <p>observable.subscribe(res => //do something with res)</p>
  </blockquote>
  
  <p>but here I'm only returning an observable, it doesn't get subscribed, but how does the guard evaluate it?</p>
  
  <p>thanks for the clarification!</p>