cscan cscan - 1 month ago 23
AngularJS Question

Angular.isArray(data) returns false for an Array

I'm using angular's $resource to get data from an API. My angular $resource is configured as follows:

Priorities : $resource (baseUrl + 'priorities/:priorityType/:uuid/all', {}, {
query : {
method: 'GET',
params: {
priorityType : '@priorityType',
uuid : '@uuid'
isArray: true

However, when calling Priorities.query a $resource:badcfg error is thrown: "Expected response to contain an array but got an object". This exception means that the API returned an object but $resource is configured to receive an array - but the API is clearly returning an array:


Digging into the angular-resource.js, the exception is thrown here:

if (angular.isArray(data) !== (!!action.isArray)) {
throw $resourceMinErr('badcfg', ...);

as expected
returns true, but strangely
returns false. What's going on here?


The response needs to be transformed from json.

Mixin.staticMethod(Type, null, 'apiResponseTransformer', function (json) {
    var data = angular.fromJson(json);
    if (angular.isArray(data)) {