title: How to make synchronous call in Angular 4 in component method
body: <p>I have an Angular 4 login Application. I have written accessing logic in login.cmponent.ts file and accessing my login.service.ts file which in turn again calls an authentication service.</p>
  
  <p>When I call authenticate method from my login component, it returns false. By the time it executes remaining code then authentication service returns true because we know Angular run code in asynchronous way.</p>
  
  <p>This is my code:</p>
  
  <p>Login Component Method:</p>
  
  <pre><code>this.loginService.setLoginData(
      new LoginModel( this.userId, this.bankId, this.password )
    ).checkIfLoginSuccessfull();
  </code></pre>
  
  <p>Login.service Method:</p>
  
  <pre><code>this.authService
    .attemptAuth(credentials);
  </code></pre>
  
  <p>Authentication Service method:</p>
  
  <pre><code>attemptAuth(credentials): void {
  
    this.restService
      .post('/authenticate', credentials)
      .subscribe(
      data =&gt; this.setAuth(data.token),
      err =&gt; this.destroy());
  
  }
  </code></pre>
  
  <p>Code is working fine. But I want to get results the moment I finish executing checkIfLoginSuccessfull(). I know I am not doing or calling methods ( Observables correctly ). </p>
  
  <p>Please help. :)</p>