title: Angular: Asynchronous Promise in Switch Statement
body: <p>I have a controller:</p>
  
  <pre><code>app.controller('myController', function ($scope, myService) {
  
      $scope.pageData = {};
  
  
      myService.promiseGetDataFromServer()
          .then(function (response) {
          $scope.pageData = response.data;
  
      }, function (reason) {
         // error has occurred.. etc...
      });
  }
  </code></pre>
  
  <p>Up to this point everything work fine. However, I would like to populate <code>$scope.pageData</code> based off of some deterministic logic. I tried this:</p>
  
  <pre><code>app.controller('myController', function ($scope, myService2, thing) {
  
     $scope.pageData = {}
  
     switch (thing)
     {
         case 'whatever':
           myService2.promiseGetWhateverFromServer()
              .then(function (response) {
              $scope.pageData = response.data;
  
           }, function (reason) {
             // error has occurred.. etc...
           });
          break;
  
          case 'something':
  
            myService2.promiseGetSomethingFromServer()
                .then(function (response) {
                $scope.pageData = response.data;
  
             }, function (reason) {
                // error has occurred.. etc...
             });
             break;
     }
  
  }
  </code></pre>
  
  <p>There were no server errors, and I logged the response and everything was good, but my view did not render since I suspect the properties of <code>$scope.pageData</code> were undefined.</p>
  
  <p>How do I get around this? I want the view to load after that switch statement has resolved.</p>