title: Angular ui-router get asynchronous data with resolve
body: <p>I want to display a form with data corresponding to the edited item. I use <code>ui-router</code> for routing. I defined a state:</p>
  
  <pre><code>myapp.config(function($stateProvider) {
  
      $stateProvider.
      .state('layout.propertyedit', {
          url: "/properties/:propertyId",
          views : {
              "contentView@": {
                  templateUrl : 'partials/content2.html', 
                  controller: 'PropertyController'
              }
          }
      });
  </code></pre>
  
  <p>In <code>PropertyController</code>, I want to set <code>$scope.property</code> with data coming from the following call (Google Cloud Endpoints):</p>
  
  <pre><code>    gapi.client.realestate.get(propertyId).execute(function(resp) {
          console.log(resp);
      });
  </code></pre>
  
  <p>I don't know if I can use <code>resolve</code> because the data are returned asynchronously. I tried </p>
  
  <pre><code>    resolve: {
          propertyData: function() {
              return gapi.client.realestate.get(propertyId).execute(function(resp) {
                  console.log(resp);
              });
          }
      }
  </code></pre>
  
  <p>First issue, the <code>propertyId</code> is undefined. How do you get the <code>propertyId</code> from the <code>url: "/properties/:propertyId"</code>?</p>
  
  <p>Basically I want to set <code>$scope.property</code> in <code>PropertyController</code> to the <code>resp</code> object returned by the async call.</p>
  
  <p>EDIT:</p>
  
  <pre><code>myapp.controller('PropertyController', function($scope, , $stateParams, $q) {
  
      $scope.property = {};
  
      $scope.create = function(property) {
      }
  
      $scope.update = function(property) {
      }
  
  function loadData() {
      var deferred = $q.defer();
  
      gapi.client.realestate.get({'id': '11'}).execute(function(resp) {
          deferred.resolve(resp);
      });
  
      $scope.property = deferred.promise;
  }
  
  });
  </code></pre>