Angular 2+ wait for method / observable to complete : <p>I need to check te back-end for authentication status, however te code completes before te observable return is finished. Which would result in an undifined. </p>

<pre><code>canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    this.isAuthenticated();        
    return this.authenticated; 
}

isAuthenticated(){
    this.loginService.isAuthenticated()
        .subscribe(status =&gt; this.authenticated = status)
} 
</code></pre>

<p>How would i change this code so i wait for the observable to complete to get the authenticated status before the code returns.</p>

<p>Note: the Angular canActivate method does not allow me to write the code as shown below:</p>

<pre><code>canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
    this.loginService.isAuthenticated()
        .subscribe(status =&gt; {
            this.authenticated = status;
            return this.authenticated;
        });
}
</code></pre>

<p>This results in the followin error:</p>

<blockquote>
  <p>Class 'AuthGuard' incorrectly implements interface 'CanActivate'.<br>
  Types of property 'canActivate' are incompatible.
      Type '(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => void' is not assignable to type '(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => boolean | Observable | Pr...'.
        Type 'void' is not assignable to type 'boolean | Observable | Promise'.</p>
</blockquote>

<p>A suggestion for a solution for this error would also be helpful.</p>
