I have a web service controller that serves up "activity" data
GET /api/activity/list
GET /api/activity/1
GET /api/activity/activity-slug-name
PUT /api/activity
DELETE /api/activity/1
It also serves up some "meta" data
GET /api/activity/meta/dates
GET /api/activity/meta/states
They all work extremely well using ngResource as they all return JSON objects. However the /api/activity/meta/dates does not
It returns an array of strings
[
"2013-06-02T17:05:16Z",
"2013-06-07T17:05:16Z",
"2013-08-17T17:05:16Z"
]
ngResource turns this into an array of char arrays see: Invalid result from ngResource request with string array
Obviously i could just split the meta functions out into some form of ActivityMetaService but i would prefer to keep it all together
My question is
Is there a way to stop ngResource from performing this overzealous object decomposition?
Or should i rais a bug with angular?
Thanks in advance
* UPDATE *
Thanks Mark for your comment. If you had placed it as an answer I would have accepted it, because it points to a bug in Angular and the other two answers do not fit with the current architecture.
While you are technical correct, no one has though of Strings as an array of chars since the mid 80s, C/C++ programmers aside :)
I have raised a ticket on github with the angular.js project, reference below
https://github.com/angular/angular.js/issues/2664
You can initialize a one-dimensional character array by specifying: A brace-enclosed comma-separated list of constants, each of which can be contained in a character. A string constant (braces surrounding the constant are optional)
A char array can be initialized by conferring to it a default size. char [] JavaCharArray = new char [ 4 ]; This assigns to it an instance with size 4.
append(char[] str) method appends the string representation of the char array argument to this sequence. The characters of the array argument are appended, in order, to the contents of this sequence. The length of this sequence increases by the length of the argument.
java String array works in the same manner. String Array is used to store a fixed number of Strings.
Our you could try to use the transformRequest
query: {
method: 'GET',
isArray: true,
transformResponse: function (data, headers) {
var tranformed = [];
[].forEach.call(eval(data), function (d) {
tranformed.push({ name: d });
});
return tranformed;
}
}
To get only an array of strings use $http service instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With