Angular.isArray(data) returns false for an Array

cscan

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:

[{"priority":"ONE","count":5,"globalCount":3037}]

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

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

as expected !!action.isArray returns true, but strangely angular.isArray(data) returns false. What's going on here?

cscan

The response needs to be transformed from json.

Mixin.staticMethod(Type, null, 'apiResponseTransformer', function (json) {
    var data = angular.fromJson(json);
    if (angular.isArray(data)) {
        return data.map(Type.build).filter(Boolean);
    }
    return Type.build(data);
})

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Array.contains returns false

Cookie array with strings returns false

in_array always returns false

is_array() returns false on SimpleXml array element

MySQL fetch_array returns false

array.includes returns false using regex

in_array function always returns false

Undefined array.length returns true not false

PDO returns false instead of empty array

instanceof function parameter returns false in Typescript/Angular

Angular 8 Observable Returns "_isScalar:false..."

RXJS in Angular 6 returns only { "_isScalar": false }

'empty?' returns 'false' for an empty array within an empty array

empty() function returns false although array contains empty array

false || false returns true

Array.every returns false instead of type error

JavaScript array.every() method returns false when using the in operator?

Is there a function which returns true or false when searching for an object in an array of objects?

checking array value with if statement always returns (output) false (else)

Angular 2 Array.map returns undefined

Testing Angular Filter That Returns An Array with Jasmine

angular 2 - http get returns empty array

@Input() property in angular component returns empty array

Angular Router route guard CanActivate always returns false

Angular Material List Option returns true, even if false

ajax returns true, but == returns false

Why is comparing an integer with array of length 1 returns true while false with array of length 2 or more?

MVC 5 Checkbox returns “False,false” or “false”

String is Nullable returns false

TOP Ranking

HotTag

Archive