title: Waiting for a promise?
body: <p>I have the following angularjs code:</p>
  
  <pre><code>$scope.clients = commonFactory.getData(clientFactory.getClients());
  if ($scope.clients.length &gt; 0) {
      $scope.sampleForm.ClientId = $scope.clients[0].ClientId;
  }
  </code></pre>
  
  <p>And the getData function in commonFactory:</p>
  
  <pre><code>factory.getData = function (method) {
      method.then(function (response) {
          return response.data;
      }, function (error) {
          $rootScope.alerts.push({ type: 'error', msg: error.data.ExceptionMessage });
      });
  };
  </code></pre>
  
  <p>The problem is that $scope.clients.length is undefined when it hits that line because of the async call.</p>
  
  <p>Is there a way to not do my length check until I know that $scope.clients has been assigned? I've looked at something like this:</p>
  
  <pre><code>$scope.clients = commonFactory.getData(clientFactory.getClients()).then(function () {
      if ($scope.clients.length &gt; 0) {
          $scope.sampleForm.ClientId = $scope.clients[0].ClientId;
      }
  });
  </code></pre>
  
  <p>Trying to chain my <code>then</code> promises, but no dice... the goal here is to have the getData method to avoid a bunch of boilerplate code for catching errors... maybe I'm going about this wrong?</p>