-1

I am trying to fetch data using query action method from a restful service using Angular $resource

When I use the default query method as MyService.query(); I have received the following error:

[$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object

Now, when overload the query action as follows error disappears which is expected.

'query': {method:'GET',IsArray:true}

But the issue is if I set IsArray to false, still there is no error. Why? I should have received the same error as in former case.

What am I missing here please?

2
  • query expects array of objects. It doesn't make sense to feed it with just an object unless you create your custom resource logic. isArray is used more for verbs like PUT to specify the response format. Commented Apr 24, 2014 at 6:03
  • @dfsq isArray can also be used with GET verb. Please elaborate on when you say "isArray is used more for verbs like PUT to specify the response format" Commented Apr 24, 2014 at 6:18

1 Answer 1

1

isArray: true is the default for query, and that's also what the error message says.

Note that in your code you write it with a capital I: IsArray.

So it's ignored by angular and your code is equivalent to 'query': {method:'GET'} which in turn is equivalent to 'query': {method:'GET', isArray:false}. That's why you don't get an error in both cases.

Sign up to request clarification or add additional context in comments.

2 Comments

The error message doesn't says that isArray: true. I corrected the case of isArray but still the problem persist. correct statement - query: { method: 'GET', isArray: true }
@Aakash " Expected response to contain an array" = isArray: true. And the server doesn't return an array. That's it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.