2

by making request to WebAPI I expect to receive string array with several values (units of measurement in this case) ["KGM", "MTR"]

Unfortunately in response I'm receiving array of resources and within array of chars

[0] Resource
    [0]: "K"
    [1]: "G"
    [2]: "M"
[1] Resource
    [0]: "M"
    [1]: "T"
    [2]: "R"

img: http://snag.gy/dDerV.jpg

Here is request which I do and how I'm carry the response

var provider = this.resource(WebAPIDataUrl, {}
, {
    GetData: {
        method: 'GET'
        , params: {
            action: "GetData"
        }, isArray: true
        , headers: {
            'Token': this.window.sessionStorage.getItem("Token")
        }
    }
});
var _success = function (resource: string[]) {
    _unitsOfMeasurements = Object.keys(resource);
};
var _error = function () {
};

provider.GetData(_success, _error);

I have also created a hook by using transformResponse to be sure that incoming data is in proper format and it's ok:

transformResponse: function(data, headers){
    return data;
}
data == '["KGM", "MTR"]'

So question is how should treat response to have nice string[] ?

Maciej Zawiasa
  • 189
  • 2
  • 6

2 Answers2

0

Can you share the raw response with us?

If you need to work with the response you have, you can obtain the strings using the array.prototype.join method.

response = [
    ['K','G','M'],
    ['M','T','R']
];

for (var i = 0; i < response.length; i++) {
    var string = response[i].join('');
    console.log(string);
}
Fenton
  • 241,084
  • 71
  • 387
  • 401
0

$resource only works with objects or arrays of objects, not strings.

You could wrap the strings in objects or as a suggestion in this thread regarding this issue says, if you want an array of strings you could use $http instead.

Gustav
  • 3,408
  • 4
  • 24
  • 41