I am facing an issue with my API that returns data to AngularJS based on a given ID. When the data is returned as JSON, AngularJS throws a 'badcfg' error, indicating that it could be due to the format of the returned data. I'm struggling to find a solution...
Factory:
app.factory('Companies', function($resource) {
return $resource('/api.php/companies/:id', {id:'@id'}, {
'query': {method: 'GET', isArray: true},
'save': {
method: 'POST',
isArray: true,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
}
},
'delete': {method: 'DELETE'}
});
});
Controller:
app.controller("ViewCompaniesController", ['$scope', 'Companies', '$routeParams', function($scope, Companies, $routeParams) {
$scope.title = 'View';
var companyId = $routeParams.id;
var theCompany = Companies.get({ id: companyId }, function() {
console.log(theCompany);
});
}]);
Error:
Error in resource configuration for action
{0}Error in resource configuration for action
. Expected response to contain an get but got an object (Request: array GET). Expected response to contain an {1} but got an {2} (Request: {3} {4})
Seeking assistance in resolving this issue. Any help would be appreciated.