title: Angular $resource data is available to view but not in the code
body: <p>I'm an angular noob and am really frustrated with a particular problem. </p>
  
  <p>I have a $resource returning data from the server, which contains key/value pairs i.e.  detail.name, detail.email etc. </p>
  
  <p>I can access this information on the view using <code>{{detail.name}}</code> notation, but I cannot access it in the code, which is driving me nuts, as I need this data to do stuff with. </p>
  
  <p>How can I access it in the backend?</p>
  
  <p>here's the code generating the data:</p>
  
  <pre><code>mydata = Appointment.get({id: $stateParams.id}, function(data){
      geocoder.geocode(data);
      $scope.detail = data;
  });
  </code></pre>
  
  <p>on the view I have the following:</p>
  
  <pre><code>&lt;address class="text-left"&gt; 
                  {{detail.address_1}}&lt;/br&gt;
                  {{detail.city}}&lt;/br&gt;
                  {{detail.postcode}}&lt;/br&gt;
                  &lt;/address&gt;
          &lt;/hr&gt;       
          &lt;p&gt; {{detail.lat}}&lt;/p&gt;
          &lt;p&gt; {{detail.lng}}&lt;/p&gt;
          &lt;p&gt; {{center}}&lt;/p&gt;
  </code></pre>
  
  <p>this is all ok. </p>
  
  <p>however, if I add <code>console.log($scope.detail.lat)</code> in the $resource callback i get undefined. </p>
  
  <p>Here is the resource definition:</p>
  
  <pre><code>angular.module('MyApp')
  .factory('Appointment', function($resource){
      return $resource('/api/admin/:id', { id: "@_id" }, {
           query: {method:'GET', isArray:true}, 
           update: { method:'PUT' }
      });
  })
  </code></pre>
  
  <p>and the geocoder factory if anyone is interested:</p>
  
  <pre><code>angular.module('MyApp')
  .factory('geocoder', ['$http','$state', function($http, $state){
  
  var geocoder ={};
  
  geocoder.geocode = function (formData){
      var myformData = {};
      var address = formData.address_1+', '+formData.city+', '+formData.postcode;
  
                  var key = 'AIzaSyACVwB4i_6ujTrdjTMI-_tnsDrf6yOfssw';
  
                  $http.get('https://maps.googleapis.com/maps/api/geocode/json?address='+address+'&amp;key='+key).
                    success(function(results, status, headers, config) {
                      var results = results.results[0];
                      formData.lat = results.geometry.location.lat;
                      formData.lng = results.geometry.location.lng;
                          myformData = formData;
                      return myformData;          
  
                       // this callback will be called asynchronously
                      // when the response is available
                    }).
                    error(function(results, status, headers, config) {
                      // called asynchronously if an error occurs
                      // or server returns response with an error status.
                    });   
  }
  
  
  return geocoder;
  
  }])
  </code></pre>
  
  <p>Can anyone help?</p>