4

Server response an array data in JSON format:

["2345","1234"]

Angular service module define:

angular.module('MySource', ['ngResource']).factory('Phone', function($resource){
  return $resource('/api/source');
});

Then I use Phone.query(); to fetch array data, but got this:

[{"0":"2","1":"3","2":"4","3":"5"},{"0":"1","1":"2","2":"3","3":"4"}]

But $http works:

$http.get('/inner/source').success(function(data){
  // data = ["2345", "1234"]
});

What's the problem? Why $resource split the array? Does I use $resource wrong way?

Thanks.

fannheyward
  • 18,599
  • 12
  • 71
  • 109

1 Answers1

4

$resource requires the response to be objects, or array of objects. Either change your response to something like this:

[{"value":"2345"},{"value":"1234"}]

or use the $http service

joakimbl
  • 18,081
  • 5
  • 54
  • 53