title: AngularJS: How to execute a controller function AFTER completion of AJAX call in a service?
body: <p>Here's my code in the service.</p>
  
  <pre><code>this.loginUser = function(checkUser) {
      Parse.User.logIn(checkUser.username, checkUser.password, {
          success: function(user) {
              $rootScope.$apply(function (){
                  $rootScope.currentUser = user;
              });
          }
      });
  };
  </code></pre>
  
  <p>Here's my code in the controller:</p>
  
  <pre><code>$scope.logIn = function(){
      authenticationService.loginUser($scope.checkUser);
          console.log($scope.currentUser)
  };
  </code></pre>
  
  <p>So, what I want to do is, execute some code AFTER the completion of AJAX call, whose success function sets the value of $scope.currentUser, which, I can use for some conditional logic (like redirecting etc)
  The success function is correctly setting the value, but the <code>console.log</code> should be executed AFTER the execution of <code>authenticationService.loginUser()</code> function.</p>