Using angular's $resource to retrieve data from an API. The configuration of the angular $resource is as follows:
Priorities: $resource (baseUrl + 'priorities/:priorityType/:uuid/all', {}, {
query: {
method: 'GET',
params: {
priorityType: '@priorityType',
uuid: '@uuid'
},
isArray: true
}
})
However, upon calling Priorities.query, a $resource:badcfg error occurs: "Expected response to contain an array but got an object". This error suggests that the API returned an object while $resource is set up to expect an array - yet the API clearly returns an array:
[{"priority":"ONE","count":5,"globalCount":3037}]
Upon investigating angular-resource.js, we find that the exception originates from this section of code:
if (angular.isArray(data) !== (!!action.isArray)) {
throw $resourceMinErr('badcfg', ...);
}
It is anticipated that !!action.isArray
would return true, but strangely angular.isArray(data)
returns false. What could be causing this inconsistency?