title: Returning a value from within a promise
body: <p>I have a service that injects a service. The child service connects to the facebook api and is suppose to return the login status of the user to the parent service. The problem I am facing is this fb api call uses a promise and I am trying to execute some logic in the parent service based on the value of the child service function call. What would be the correct way of doing this?</p>
  
  <p>This is what I tried:</p>
  
  <p>facebook.service.ts </p>
  
  <p>Note, the below code successfully connects to the facebook api and outputs "connected" as it should**</p>
  
  <pre><code>checkLoginStatus() {
          this.FB.getLoginStatus( (response) =&gt; {
              console.log(response.status); //outputs "connected"
          });
  
  }
  </code></pre>
  
  <p>However, I am trying to return the value contained within the promise's response to the parent service, so I modified the code as follows... and getting the error: </p>
  
  <pre><code>Uncaught (in promise): TypeError: Cannot read property 'getLoginStatus' of undefined
  </code></pre>
  
  <p>facebook.service.ts</p>
  
  <pre><code> FB:any;
  
      constructor() {
          facebook().then((FB) =&gt; {
              // Initialize SDK
              FB.init({
                  appId      : '1111111111111111',
                  cookie     : true,  // enable cookies to allow the server to access
                                      // the session
                  xfbml      : true,  // parse social plugins on this page
                  version    : 'v2.8' // use graph api version 2.5
              });
  
              this.FB = FB;
  
          });
      }
  
      checkLoginStatus() {
          this.FB.getLoginStatus( (response) =&gt; {
             return response.status; //"connected"
          });
      }
  </code></pre>
  
  <p>home.service.ts</p>
  
  <pre><code>constructor(@Inject(FacebookService) private fb:FacebookService) {
      this.authenticateFacebook();
  }
  
  authenticateFacebook() {
      this.fb.checkLoginStatus().then( (response) =&gt; {
          console.log(response); //should output connected
      });
  }
  </code></pre>