Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS / Restangular routing "Cannot set property 'route' of undefined"
    text
    copied!<p>I have a AngularJS-based frontend using restangular to fetch records from a Django backend I've built.</p> <p>I'm making a call for a client list with the following:</p> <pre><code>var app; app = angular.module("myApp", ["restangular"]).config(function(RestangularProvider) { RestangularProvider.setBaseUrl("http://172.16.91.149:8000/client/v1"); RestangularProvider.setResponseExtractor(function(response, operation) { return response.objects; }); return RestangularProvider.setRequestSuffix("/?callback=abc123"); }); angular.module("myApp").controller("MainCtrl", function($scope, Restangular) { return $scope.client = Restangular.all("client").getList(); }); </code></pre> <p>Chrome is showing the backend returning data with an HTTP 200:</p> <pre><code>abc123({ "meta": { "limit": 20, "next": "/client/v1/client/?callback=abc123&amp;limit=20&amp;offset=20", "offset": 0, "previous": null, "total_count": 2 }, "objects": [{ "id": 1, "name": "Test", "resource_uri": "/client/v1/client/1/" }, { "id": 2, "name": "Test 2", "resource_uri": "/client/v1/client/2/" }] }) </code></pre> <p>But once that happens I'm seeing the following stack trace appear in Chrome's console:</p> <pre><code>TypeError: Cannot set property 'route' of undefined at restangularizeBase (http://172.16.91.149:9000/components/restangular/src/restangular.js:395:56) at restangularizeCollection (http://172.16.91.149:9000/components/restangular/src/restangular.js:499:35) at http://172.16.91.149:9000/components/restangular/src/restangular.js:556:44 at wrappedCallback (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:6846:59) at http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:6883:26 at Object.Scope.$eval (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8057:28) at Object.Scope.$digest (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:7922:25) at Object.Scope.$apply (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:8143:24) at done (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:9170:20) at completeRequest (http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js:9333:7) angular.js:5754 </code></pre> <p>I did a breakpoint on line 395 in in restangular.js:</p> <pre><code>L394 function restangularizeBase(parent, elem, route) { L395 elem[config.restangularFields.route] = route; </code></pre> <p>The first time it hits the breakpoint <code>elem</code> is just an object and <code>route</code> has the value of <code>client</code>.</p> <p>The second time the breakpoint is hit <code>elem</code> is undefined and <code>route</code> has the value of <code>client</code>.</p> <p>Any ideas why <code>elem</code> would be undefined the second time around?</p>
 

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