title: Explanation of asynchronous data loading in AngularJS
body: <p>Below the example code in a controller with 2 console.log instructions.
  After accessing the page in browser, the list of users appears, all is displayed well. But the result of console.log is :</p>
  
  <p>The first one: <code>after loadAll() function call = 0</code></p>
  
  <p>The second one: <code>End of loadAll() function = 8</code></p>
  
  <pre><code>angular.module('tessicommunicationApp')
  .controller('UserManagementController', ['$scope', '$filter', '$log', 'Principal', 'User', 'ParseLinks', 'Language', 'NgTableParams', function ($scope, $filter, $log, Principal, User, ParseLinks, Language, NgTableParams) {
              $scope.users = [];
              $scope.authorities = ["ROLE_USER", "ROLE_ADMIN", "ROLE_TC_ADMIN", "ROLE_TC_GES_ADM", "ROLE_TC_SUI_TRA", "ROLE_TC_CONS"];
              Language.getAll().then(function (languages) {
                  $scope.languages = languages;
              });
  
              Principal.identity().then(function (account) {
                  $scope.currentAccount = account;
              });
              $scope.page = 1;
              $scope.loadAll = function () {
                  User.query({
                      page : $scope.page - 1,
                      size : 20
                  }, function (result, headers) {
                      $scope.links = ParseLinks.parse(headers('link'));
                      $scope.totalItems = headers('X-Total-Count');
                      $scope.users = result;
                      console.log("End of loadAll() function = " + $scope.users.length);
                  });
              };
  
              $scope.loadPage = function (page) {
                  $scope.page = page;
                  $scope.loadAll();
              };
              $scope.loadAll();
              console.log("after loadAll() function call = " + $scope.users.length);
          }
      ]);
  </code></pre>
  
  <p>My question is simple : why the first one log print "0" whereas loadAll() method is called just before.</p>