mercredi 1 avril 2015

Expected response to contain an object but got an array for GET action


Vote count:

0




I'm getting this error "Error: [$resource:badcfg] Error in resource configuration for action 'get'. Expected response to contain an object but got an array"


and I don't know how to fix it. I have this service



angular.module('messages').factory('Messages', ['$resource',
function ($resource) {
return $resource('api/messages/:username', {
username: '@username'
});
}]);


and this in controller:



$scope.findOne = function () {
$scope.messages = Messages.get({
username: $routeParams.username
});

console.log($scope.messages);
};


For this route I have in API controller this



exports.read = function (req, res) {
res.json(req.message);
};


I know that I have to use $resource action isArray = true, but I don't know where to put it. I tried to do something like this:



angular.module('messages').factory('Messages', ['$resource',
function ($resource) {
return $resource('api/messages/:username', {
username: '@username'
},
{'query': {method: 'GET', isArray: true}});
}]);


but without result and still same error.



asked 1 min ago







Expected response to contain an object but got an array for GET action

Aucun commentaire:

Enregistrer un commentaire