起初我有这个,但得到了错误Expected response to contain an object but got an array
:
angular.module('homeModule').factory("TodosFactory", ['$resource', function ($resource) {
return $resource('/api/todos/:todoId', {
todoId: '@_id'
});
}]);
所以我改成这样:
angular.module('homeModule').factory("TodosFactory", ['$resource', function ($resource) {
return $resource('/api/todos/:todoId', {
todoId: '@_id'
}, {'save': {method: 'POST', isArray:true}}); // this line is added
}]);
我将一个项目保存到数据库,并返回对象列表作为结果。返回一个 JSON 数组,但我收到此错误。
有什么建议么?