0

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;
});

1 Answer 1

1

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;
});
Sign up to request clarification or add additional context in comments.

Comments

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.