Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have a Web API which is returning a response in JSON, in this format:

{
  "email": "[email protected]",
  "password": null,
  "accessLevel": 2
}

I am trying to access the accessLevel field within that response, but I am getting this Angular error:

Error in resource configuration for action `query`. Expected response to contain an array but got an object (Request: GET http://localhost:51608/api/[email protected]...)

This is my Angular resource code (below), I just added the isArray false to attempt to solve the issue:

function userRoleResource($resource, appSettings) {
    return $resource(appSettings.serverPath + "/api/UserRole?email=:email", { email: '@email' },
    {
        get: {
            method: 'GET',
            isArray: false
        }
    });
}

And this is how I am attempting to use the data:

userRoleResource.query({ email: vm.userData.email },
   function (data) {
      vm.userData.accessLevel = data.AccessLevel;
});
share|improve this question
up vote 1 down vote accepted

you're specifying that the 'get' function is not an array, but you're using the 'query' function.

try this:

userRoleResource.get({ email: vm.userData.email },
    function (data) {
        vm.userData.accessLevel = data.AccessLevel;
});
share|improve this answer
    
thanks, that's it, such a silly mistake :) – Ryan S Apr 19 '16 at 20:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.