javascript - Expected response to contain an object but got an array for GET action -
i'm getting error "error: [$resource:badcfg] error in resource configuration action 'get'. expected response contain object got array
"
and don't know how fix it. have service
angular.module('messages').factory('messages', ['$resource', function ($resource) { return $resource('api/messages/:username', { username: '@username' }); }]);
and in controller:
$scope.findone = function () { $scope.messages = messages.get({ username: $routeparams.username }); console.log($scope.messages); };
for route have in api controller this
exports.read = function (req, res) { res.json(req.message); };
i know have use $resource action isarray = true, don't know put it. tried this:
angular.module('messages').factory('messages', ['$resource', function ($resource) { return $resource('api/messages/:username', { username: '@username' }, {'query': {method: 'get', isarray: true}}); }]);
but without result , still same error.
in controller:
$scope.findone = function () { $scope.messages = messages.query({ username: $routeparams.username }); console.log($scope.messages); };
query
instead of get
, should solve it.
Comments
Post a Comment