title: $resource callback function in angularjs
body: <p>I set up a method to be called by an ng-click event in my html:</p>
  
  <pre><code>&lt;div ng-repeat="section in model.sections"&gt;
      &lt;a ng-click="updateSection($index)"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Then in my javascript file, I had the following service: </p>
  
  <pre><code>.factory('Sections', function($resource){
      return{
          onUnits: $resource('/api/sections/:uuid/units', {uuid:'@sectionUUID'}, {
              get: {method: 'GET', params:{uuid: '@uuid'}, isArray:true}
          }
      }
  }
  </code></pre>
  
  <p>The method being called from the html is:</p>
  
  <pre><code>$scope.updateSection = function(index){
      $scope.model.sections[index].sectionUnits = Sections.onUnits.get({uuid: $scope.model.sections[index].sectionUUID}
          ,console.log($scope.model.sections[index])
          );
      }
  </code></pre>
  
  <p>before this update happens, </p>
  
  <pre><code>$scope.model.sections[0].sectionUnits == ['d1','d2']
  </code></pre>
  
  <p>which is the list of id's of units associated with this section. This method basically updates this list with the real <code>unit</code> objects that looks like:</p>
  
  <pre><code>.sectionUnits = [{unitUUID: 'd1',
                    materials: ['m1','m2','m3']
                    }, {... }]
  </code></pre>
  
  <p>in my browser, the code above returns the updated <code>section</code> object that I was looking for, with all the <code>unit</code> objects nested under the <code>section</code>.</p>
  
  <p>However, what I really wanted, was to implement a callback that takes the list of id's of all the <code>materials</code> associated with the unit in this updated <code>section</code> object, and retrieve them.</p>
  
  <p>If I try that, and have the following call back instead, I get the list of <code>sectionUnits</code> that's still just the id's:</p>
  
  <pre><code>$scope.updateSection = function(index){
      $scope.model.sections[index].sectionUnits = Sections.onUnits.get({uuid: $scope.model.sections[index].sectionUUID}
          ,console.log($scope.model.sections[index].sectionUnits)
          );
      }
  </code></pre>
  
  <p>I have looked through a lot of SO threads and the original doc, but am kind of stuck at this point.</p>
  
  <p>Thanks!</p>