yesiamaguest yesiamaguest - 5 months ago 26
AngularJS Question

How can I send a response from Web API to an angular resource query?

I have the following Angular query.

services.factory('UserFactory', function ($resource) {
return $resource('/api/users', {

}, {
query: { method: 'GET' }
});
});


and

$scope.searchedUsers = UserFactory.query({ searchString: "test" });


From Asp.Net Web Api, I'm returning

return Request.CreateResponse<List<User>>(HttpStatusCode.OK, users);


Then Angular throws the error


Response does not match configured parameter Error in resource
configuration for action
object
. Expected response to contain an
array but got an {2} (Request: {3} {4})


But when I look at the response in developer tools, it appears to be an array:

[{"Id":0,"name":"test"},{"Id":0,"name":"test"}]


Why is it throwing this error?

Answer

Set your factory to

query: { method: 'GET',isArray:true}
Comments