Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>$resource is not synchronous although this syntax might suggest that it is:</p> <pre><code>$scope.twitterResult = $scope.twitter.get(); </code></pre> <p>What is going on here is that call to the AngularJS will, after call to <code>twitter.get()</code>, <strong>return immediately with the result being an empty array. Then, when the async call is finished and real data arrives from the server, the array will get updated with data</strong>. AngularJS will simply keep a reference to an array returned and will fill it in when data are available.</p> <p>Here is the fragment of $resource implementation where the "magic" happens: <a href="https://github.com/angular/angular.js/blob/master/src/ngResource/resource.js#L372">https://github.com/angular/angular.js/blob/master/src/ngResource/resource.js#L372</a></p> <p>This is described in the <a href="http://docs.angularjs.org/api/ngResource.%24resource"><strong>$resource documentation</strong></a> as well:</p> <blockquote> <p>It is important to realize that invoking a $resource object method immediately returns an empty reference (object or array depending on <code>isArray</code>). Once the data is returned from the server the existing reference is populated with the actual data. This is a useful trick since usually the resource is assigned to a model which is then rendered by the view. Having an empty object results in no rendering, once the data arrives from the server then the object is populated with the data and the view automatically re-renders itself showing the new data. This means that in most case one never has to write a callback function for the action methods.</p> </blockquote>
 

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