title: Binding and getting values async in AngularJS
body: <p>I am new to AngularJS and still relativly new to JS at all. I tried to implement an angularjs project with login informations, etc. <br><br>Now I call by http request an API and get an answer with the user and the users objects. When I open the site, the console.logs show an result of 0 users and user=undefined. But when I open the objects in the console window, they are filled. So that means, the results are not there at the opening of the page, but are loaded async. So far, so clear. <br><br>But I thought the bindings in AngularJS were bindings that update themselves as soon as the value changes. I looked around for a while and found as answer that I should use a factory, but I don't know how. Can someone point me in the right direction please?</p>
  
  <p>HTML</p>
  
  <pre><code>&lt;h1&gt;Hi {{vm.user.firstname}}!&lt;/h1&gt;
  &lt;p&gt;You're logged in! Test{{testService.test}}!&lt;/p&gt;
  &lt;h3&gt;All registered users:&lt;/h3&gt;
  &lt;ul&gt;
      &lt;li ng-repeat="user in vm.allUsers"&gt;
          {{user.username}} ({{user.firstname}} {{user.lastname}})
          - &lt;a ng-click="vm.deleteUser(user.id)"&gt;Delete&lt;/a&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>controller.js</p>
  
  <pre><code>angular
      .module('app')
      .controller('HomeController', HomeController);
  
  HomeController.$inject = ['UserService', '$rootScope'];
  function HomeController(UserService, $rootScope) {
      var vm = this;
  
      vm.user = null;
      vm.allUsers = [];
      vm.deleteUser = deleteUser;
  
      initController();
  
      function initController() {
          loadCurrentUser();
          loadAllUsers();
          log(vm);
      }
  
      function loadCurrentUser() {
          UserService.GetByUsername($rootScope.globals.currentUser.username).then(resolve =&gt; {
              vm.user = resolve.message;
          });
      }
  
      function loadAllUsers() {
          UserService.GetAll().then(resolve =&gt; {
              vm.allUsers = resolve.message;
          });
      }
  
      function deleteUser(id) {
          UserService.Delete(id).then(() =&gt; {
              loadAllUsers();
          });
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> I found the solution. It is not the asyncronicity that makes a problem here. It is simply the reading of the returned data.</p>
  
  <pre><code>vm.allUsers = resolve.message.recodsets;
  </code></pre>
  
  <p>That gives all Recordsets for going through with ng-repeat and to get the one logged in user it was:</p>
  
  <pre><code>vm.user = resolve.message.recodset[0];
  </code></pre>
  
  <p>That is a little bit embarrassing but this way it works.</p>