Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The pattern that I have encountered the most is to create a resource object, then make assignments in the callback. So instead of your current <code>updateSections</code> function, you would have:</p> <pre><code>$scope.updateSection = function(index) { Sections.onUnits.get( {uuid: $scope.model.sections[index].sectionUUID}, function(results) {$scope.model.sections[index].sectionUnits = results} ) } </code></pre> <p>I think that in your code the results of the <code>GET</code> don't actually get assigned, which is why you're getting back the original array of ids.</p> <p>Note that the assignment only occurs on successful <code>GET</code> of the resource. You should have a separate callback to handle any errors.</p> <p>Also remember that services are singletons, so if you're passing it around, be careful to not change <code>Sections</code>, or it'll change everywhere else around.</p> <p>If you wanted to chain requests such that after retrieving a section, you get the materials, then you would do that in your callback, right after the assignment.:</p> <pre><code>$scope.updateSection = function(index) { Sections.onUnits.get( {uuid: $scope.model.sections[index].sectionUUID}, function(results) { $scope.model.sections[index].sectionUnits = results; // Should contain some looping mechanism since results is an array. $scope.getMaterials(results); } ) } </code></pre> <p>A couple of other notes on your code:</p> <ul> <li>Something seems wrong about your initial method call to get the resource. At that point, you say that the <code>sectionUnits</code> object is an array of strings, but your <code>updateSection()</code> method call tries to reference the array as an object. You say that you can get a console printout, so I'm guessing that it works, but you just made a typo</li> <li>It seems like a bad idea to mutate the sectionUnits object from an array of strings to an array objects. Maybe initialize it as <code>.sectionUnits = [{unitUUID:'d1'}, {unitUUID:'d2'}]</code>?</li> <li>You may want to take a look at <a href="https://github.com/mgonto/restangular" rel="nofollow">Restangular</a>, which basically wraps <code>$resource</code> to be a bit more user friendly. I've found it to be really easy to work with.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload