title: restangular/django: "TypeError: Object #<Resource> has no method 'push'" (RestangularProvider.setResponseExtractor not being called?)
body: <p>Update 2</p>
  
  <p>I upgraded from 0.6.1 to 1.0.9 which fixed the issue.  It appears as thought there were two fixes  in versions 0.8.7 and 0.8.8 that were needed to make this work.  In 0.8.7 it does make the call to the reourceExtractor, but still errors out w/ this trace:</p>
  
  <blockquote>
    <p>Error: $digest already in progress
        at Error ()
        at beginPhase (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8334:15" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8334:15</a>)
        at Object.$get.Scope.$apply (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8136:11" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8136:11</a>)
        at HTMLDivElement.ngEventDirectives.(anonymous function) (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:12986:17" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:12986:17</a>)
        at event.preventDefault (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:1992:10" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:1992:10</a>)
        at Array.forEach (native)
        at forEach (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:130:11" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:130:11</a>)
        at eventHandler (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:1991:5" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:1991:5</a>)
        at HTMLDivElement.forEach.bind.events.(anonymous function) (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:2067:15" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:2067:15</a>)
        at event.preventDefault (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:1992:10" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:1992:10</a>)</p>
  </blockquote>
  
  <p>however 0.8.8 seems to have cleared all that up.  I am going to continue to poke around and see if there are any other oddities.</p>
  
  <p>I don't know how I ended up with such an old version of restangular.</p>
  
  <hr>
  
  <p>Update:</p>
  
  <p>so tracing through the javascript</p>
  
  <pre><code>angular-resource.js::ResourceFactory
  </code></pre>
  
  <p>is being called the success variable is the anonymous function from </p>
  
  <pre><code>restangular.js::fetchFunction
  </code></pre>
  
  <p>where the responseExtractor is the function I set up in my app.  So this all looks good??? in</p>
  
  <pre><code>angular-resource.js::ResourceFactory
  </code></pre>
  
  <p>the REST call is made and the data variable contains the correct REST response.  It is falling apart here in the same function:</p>
  
  <pre><code>if (data) {
      if (action.isArray) {
          value.length = 0;
          forEach(data, function(item) {
              value.push(new Resource(item));
          });
      } else {
          copy(data, value);
      }
  }
  </code></pre>
  
  <p>the error is occurring @ value.push(new Resource(item));  where value is essentially the JSON rest response.  </p>
  
  <p>I read that angular resource requires you to define the rest resource and response and part of the definition is defining the array portions.  I don't know if that is the root cause - but I thought restangular took care of  that for me.  Still more digging to do.  Any help is -still- appreciated. </p>
  
  <p>Thx</p>
  
  <hr>
  
  <p>So I am learning Angular and Django simultaneously.  I have used Django rest services to build a service to return some simple JSON.  That part is working fine, but I cannot seem to get it hooked up with /restangular.  The REST call is happening, and json is being returned - but the responseExtractor doesn't seem  to be getting called.  I have been fidgeting around and can't seem to put my finger on it.</p>
  
  <p>Thank you in advance</p>
  
  <p>adding the call stack:</p>
  
  <blockquote>
    <p>TypeError: Object # has no method 'push'
        at U (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:10:257" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:10:257</a>)
        at new Resource (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:350:9" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:350:9</a>)
        at <a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:407:32" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:407:32</a>
        at m (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:6:494" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:6:494</a>)
        at <a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:406:19" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:406:19</a>
        at h (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:78:33" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:78:33</a>)
        at <a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:78:266" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:78:266</a>
        at Object.e.$eval (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:88:347" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:88:347</a>)
        at Object.e.$digest (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:86:198" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:86:198</a>)
        at Object.e.$apply (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:88:506" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js:88:506</a>)</p>
  </blockquote>
  
  <p>non min stack</p>
  
  <blockquote>
    <p>TypeError: Object # has no method 'push'
        at copy (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:593:21" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:593:21</a>)
        at new Resource (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:350:9" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:350:9</a>)
        at angular.module.factory.Resource.(anonymous function) (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:407:32" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:407:32</a>)
        at forEach (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:137:20" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:137:20</a>)
        at angular.module.factory.Resource.(anonymous function) (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:406:19" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js:406:19</a>)
        at deferred.promise.then.wrappedCallback (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:6846:59" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:6846:59</a>)
        at ref.then (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:6883:26" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:6883:26</a>)
        at Object.$get.Scope.$eval (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8057:28" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8057:28</a>)
        at Object.$get.Scope.$digest (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:7922:25" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:7922:25</a>)
        at Object.$get.Scope.$apply (<a href="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8143:24" rel="nofollow">http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8143:24</a>)</p>
  </blockquote>
  
  <p>looking at the code, the responseExtractor method is stored in the variable "a" which I don't see in the stack.</p>
  
  <p>JSON</p>
  
  <pre><code>{
      "count": 2
      , "next": null
      , "previous": null
      , "results": [{"file": "tb.png", "caption": "dfsdffs", "id": 1}
          , {"file": "tannin_tasting.jpg", "caption": "tannin tasting", "id": 2}
      ]
  }
  </code></pre>
  
  <p>Javascript (edit: fixed cut paste error mentioned by sza)</p>
  
  <pre><code>    angular.module('spaceJam', ['ui.bootstrap', 'restangular'])
          .config(function(RestangularProvider) {
               RestangularProvider.setResponseExtractor(function(response, operation) {
                   alert('here')
                   if (operation === "getList") {
  
                      var newResponse = response.results;
                      newResponse._resultmeta = {
                          "count": response.count,
                          "next": response.next,
                          "previous": response.previous
                      };
                      return newResponse;
                  }
  
                  return response;
               });
          });
  
  
  var CarouselCtrl = function ($scope, Restangular) {
  
      Restangular.all('images/?format=json').getList().then(function(images) {
          alert(1)
          $scope.items = images;
      });
  
  
      $scope.myInterval = 3000;
      $scope.template = "/resources/angularViews/carousel.html"
      var slides = $scope.slides =  [
          {'type': 'image', 'name': '/resources/img/pinot_noir_glass.jpg'}
          , {'type': 'image', 'name': '/resources/img/toast1.jpg'}
          , {'type': 'image', 'name': '/resources/img/vinyard1.jpg'}
          , {'type': 'image', 'name': '/resources/img/tannin_tasting.jpg'}
      ]
  }
  </code></pre>