Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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[] ?

share|improve this question

2 Answers 2

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);
}
share|improve this answer

$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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.