当前位置: 动力学知识库 > 问答 > 编程问答 >

angularjs - 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?

网友答案:

Set your factory to

query: { method: 'GET',isArray:true}
分享给朋友:
您可能感兴趣的文章:
随机阅读: