Note that there are some explanatory texts on larger screens.

plurals
  1. PO$resource callback function in angularjs
    primarykey
    data
    text
    <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>
    singulars
    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. This table or related slice is empty.
    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