title: Function that returns true if http.get was successful at Guard canActivate function
body: <p>I want to create a function that will return true if http.get was successful, otherwise return false. I was trying something like that:</p>
  
  <pre><code>  isOk() {
      let isOk;
      this.http.get('ip/api/isOk')
        .subscribe(x =&gt; { isOk = true; }, 
        (err) =&gt; { isOk = false; });
      return isOk;
    }
  </code></pre>
  
  <p>But it returns <code>undefined</code>. I know it's an async function so it returns a value before <code>http.get</code> finishes. How can I create a function that returns true/false after "receiving" data from a REST API?</p>
  
  <p>edit:
  I want to use this function at Guard <code>canActivate</code> function.
  I dont know how can I construct IF statement with observable.</p>
  
  <pre><code>  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        let x = this.someService.isOk();
        if(...){//if isOk return true
           return true;
        }else{
          this.router.navigate(['/login']);
        }
    }
  </code></pre>