title: AngularJS How to execute function after some function finish?
body: <p>I have some page which contain register with facebook button which I set hidden with <code>ng-hide="fbLoggedIn"</code> and form input which I set hidden with <code>ng-show="fbLoggedIn"</code></p>
  
  <p>My goal is register with facebook button will hide if <code>fbLoggedIn</code> set to true and form input will show if <code>fbLoggedIn</code> set to true.</p>
  
  <p>register facebook button <code>ng-click="registerFb()"</code> execute this function</p>
  
  <pre><code>$scope.registerFB = function () {
  
          authService.fbLogin();
          $scope.fbLoggedIn = authService.fb_logged_in();
          console.log($scope.fbLoggedIn); //this show false even `fb_access_token` not null
  
      }
  </code></pre>
  
  <p>Here is my <code>authService.fbLogin and authService.fb_logged_in</code> function</p>
  
  <pre><code>authService.fbLogin = function () {
  
          var FB = window.FB;
  
          FB.login(function(response) {
          console.log(response);
  
      if (response.authResponse) {
          sessionService.set('fb_id', response.authResponse.userID);
          sessionService.set('fb_access_token', response.authResponse.accessToken);
          sessionService.set('fb_expiration_date', new Date(new Date().getTime() + response.authResponse.expiresIn * 1000).toISOString());
       //console.log('Welcome!  Fetching your information.... ');
       FB.api('/me', function(response) {
         console.log('Good to see you, ' + response.name + '.');
           console.log(response);
  
  
       });
  
      } else {
       console.log('User cancelled login or did not fully authorize.');
       //console.log(response);
      }
      });
  
  };
  
  authService.fb_logged_in = function () {
      if(sessionService.get('fb_access_token') != null){
          return true;
      }else {
          return false;       
      }
  };
  </code></pre>
  
  <p>In other function I try to check if <code>fb_access_token</code> is not null, just to make sure something wrong with my logic, and the result is <code>true</code>.</p>
  
  <p>With above debuggin I can say that <code>$scope.fbLoggedIn = authService.fb_logged_in();</code> execute before <code>authService.fbLogin();</code> finish.</p>
  
  <p>So how I can execute <code>$scope.fbLoggedIn = authService.fb_logged_in();</code> after <code>authService.fbLogin();</code> finish? maybe how to achieve my goal?</p>