title: Connect the authentication service with the AuthGuard (simple issue)
body: <p>I guess it's quite simple issue, but unfortunately I don't really know how to deal with it.</p>
  
  <p>I'm trying to connect my <code>UserAuthenticationService</code> service with the <code>ActivationGuard</code>.</p>
  
  <p><code>UserAuthenticationService.ts</code>:</p>
  
  <pre><code>import {Injectable} from '@angular/core';
  import {Http} from '@angular/http';
  
  @Injectable()
  export class UserAuthenticationService {
      isUserAuthenticated: boolean = false;
      username: string;
  
      constructor(private http: Http) {
      }
  
      authentication() {
          this.http.get(`http://localhost/api/auth/isLogged/${this.username}`)
              .subscribe(res =&gt; { //^^returns true or false, depending if the user is logged or not
                      this.isUserAuthenticated = res.json();
                  },   
                  err =&gt; {
                      console.error('An error occured.' + err);
                  });
      }
  
  
  }
  </code></pre>
  
  <p><code>ActivationGuard.ts</code></p>
  
  <pre><code>import {Injectable} from '@angular/core';
  import {Router, RouterStateSnapshot, ActivatedRouteSnapshot} from '@angular/router';
  import {Observable} from 'rxjs/Observable';
  import {UserAuthenticationService} from './UserAuthenticationService';
  
  interface CanActivate {
      canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable&lt;boolean&gt;|Promise&lt;boolean&gt;|boolean
  }
  
  @Injectable()
  export class WorksheetAccessGuard implements CanActivate {
  
      constructor(private router: Router, private userService: UserAuthenticationService) {
      }
  
      public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
  
          if (this.userService) {
              this.router.navigate(['/']);
              return false;
          }
          return true;
      }
  }
  </code></pre>
  
  <h1>Note</h1>
  
  <p>It works great, if I just use <code>localStorage</code> to store the information if the user is logged or not:</p>
  
  <pre><code>public canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
  
      if (!localStorage.getItem('currentUser')) {
          this.router.navigate(['/']);
          return false;
      }
      return true;
  }
  </code></pre>
  
  <p>But how can I connect the service with the guard? Looking forward for any kind of help. Thank you in advance.</p>
  
  <p>If you need any more information, please let me know and I will edit my post.</p>