I have the following in my controller file:
var Subject = $resource(\'/api/TestAccounts/:action\', { applicationId: 3 }, {
\'getSelect\': { method: \'GET\
I just changed MyService.get(...)
to MyService.query(...)
because .get()
expects an object and .query()
expects an array.
You need to set the paramater isArray
to true in your resource definition if you are returning an array from the server.
var Subject = $resource('/api/TestAccounts/:action', { applicationId: 3 }, {
'getSelect': { method: 'GET', isArray: true, params: { action: 'GetSelect' } }
});
See: AngularJS $resource API
By default, GET expects an object {}, QUERY expects an array[]. In your case, Web API returns an array for GET, so you need to set isArray flag for GET as true. If your Web API returned an object, then you would not need to reset that flag because it is GET's default behavior.
I know this post is a bit stale but I found a solution when I ran into this problem today. Following the post below, I implemented joelwreed's solution (half way down the thread). It does a check that the destination is an array before trying to push, which fixes the issue.
Link to issue filed on github