Friday, November 15, 2013

Expected response to contain an array but got an object.

If you are getting this Angular error then you need to use a .get from $resource in lieu of .query as suggested here, refactoring something like this:

var composite = "";
Assets.query({id: "whatever"}, function(outerData) {
   outerData.forEach(function(innerData) {
      composite = composite + innerData[0];
   });

 
 

...to something like this:

var composite = "";
Assets.get({id: "whatever"}, function(outerData) {
   for (var key in outerData) {
      if ((key).indexOf("$")) {
         composite = composite + outerData[key];
      }
   }

 
 

...note that we are now looping through a dictionary in lieu of an array.

No comments:

Post a Comment