Php Restangular中Restler响应出错

Php Restangular中Restler响应出错,php,api,rest,restler,restangular,Php,Api,Rest,Restler,Restangular,我已经做了几天了,但似乎无法让它发挥作用。我的问题是,我正在使用Restler(版本3)作为API,并在我的前端重新启动了Angular,我得到了以下错误: Error: can't convert undefined to object restangularizeBase@http://localhost/vendor/restangular/src/restangular.js:436 restangularizeCollection@http://localhost/vendor/res

我已经做了几天了,但似乎无法让它发挥作用。我的问题是,我正在使用Restler(版本3)作为API,并在我的前端重新启动了Angular,我得到了以下错误:

Error: can't convert undefined to object restangularizeBase@http://localhost/vendor/restangular/src/restangular.js:436 restangularizeCollection@http://localhost/vendor/restangular/src/restangular.js:552 createServiceForConfiguration/fetchFunction/<@http://localhost/vendor/restangular/src/restangular.js:610 Qc/e/j.promise.then/h@http://localhost/vendor/angular/angular.min.js:78 Qc/g/<.then/<@http://localhost/vendor/angular/angular.min.js:78 e.prototype.$eval@http://localhost/vendor/angular/angular.min.js:88 e.prototype.$digest@http://localhost/vendor/angular/angular.min.js:86 e.prototype.$apply@http://localhost/vendor/angular/angular.min.js:88 e@http://localhost/vendor/angular/angular.min.js:95 p@http://localhost/vendor/angular/angular.min.js:98 Yc/</t.onreadystatechange@http://localhost/vendor/angular/angular.min.js:99
我将为API访问的用户类对象(现在我只返回一个测试示例)

最后是我的app.js文件

'use strict';

var app = angular.module('cma',['restangular']);

app.config(function(RestangularProvider) {
    RestangularProvider.setBaseUrl('/api');
    RestangularProvider.setExtraFields(['name']);
    RestangularProvider.setResponseExtractor(function(response,operation) {
        return response.data;
    });
});

app.run(['$rootScope','Restangular',function($rootScope,Restangular) {
    var userResource = Restangular.all('session');
    $scope.test = userResource.getList(); // This is where the error is happening 
}]);
API返回以下JSON响应(取自Firebug:

GET http://localhost/api/user 200 OK 96ms
):


我看不到任何会引起问题的事情。任何帮助都将不胜感激

我是restanglar:)的创建者

问题是您使用的是responseInterceptor,实际上返回的是一个数组

因此,您的服务器正在返回一个数组。您的responseInterceptor获取它,然后返回数组的
数据
变量。因为它是未定义的,所以未定义被发送到Restangular,因此您会得到该错误

移除responseInterceptor,一切都将开始工作:)

胜过

'use strict';

var app = angular.module('cma',['restangular']);

app.config(function(RestangularProvider) {
    RestangularProvider.setBaseUrl('/api');
    RestangularProvider.setExtraFields(['name']);
    RestangularProvider.setResponseExtractor(function(response,operation) {
        return response.data;
    });
});

app.run(['$rootScope','Restangular',function($rootScope,Restangular) {
    var userResource = Restangular.all('session');
    $scope.test = userResource.getList(); // This is where the error is happening 
}]);
GET http://localhost/api/user 200 OK 96ms
[
    {
        "first_name": "John",
        "last_name": "Smith",
        "role": "supervisor"
    },
    {
        "first_name": "Matt",
        "last_name": "Doe",
        "role": "employee"
    }
]