title: AngularJS - Asynchronous call to Facebook API
body: <p>I'am trying to call a Facebook API with AngularJS.</p>
  
  <p>The problem is that all calls from FB API is Asynchronous, so I need to know when my query on facebook is avaliable to use in agularjs.</p>
  
  <p>For this, I call this method in my controller:</p>
  
  <p><code>Facebook.getLoginStatus();</code></p>
  
  <p>which Facebook is my service, defined as:</p>
  
  <blockquote>
    <p>app.factory('Facebook', function() { </p>
  
  <pre><code>    getLoginStatus: function() {
  
          FB.getLoginStatus(function(stsResp) {
              console.log(stsResp);
              if(stsResp.authResponse) {
                  // User is already logged in
                  return true;
              } else {
                  // User is not logged in.
                  return false;
              }
          });
      }
  </code></pre>
    
    <p>}</p>
  </blockquote>
  
  <p>What I want in this case is to check if user is logged. If true, I'll show some options, otherwise, I'll show the Login button.</p>
  
  <p>I've already try to use $q.defer() functions, promises, factorys to watch response data, everything. But anything works as I want. I've checked some development examples based on <a href="http://www.egghead.io/" rel="nofollow">Egghead.io</a> examples, but I think that I'm not fully understand asynchronous calls in angularjs.</p>
  
  <p>Thanks in advance.</p>