yesiamaguest yesiamaguest - 1 year ago 101
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' }


$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
. 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:


Why is it throwing this error?

Answer Source

Set your factory to

query: { method: 'GET',isArray:true}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download