2

i've the following ngResource defined:

angular.module('LicenseServices', ['ngResource']).
    factory('License', function ($resource) {
        return $resource('api/licenses/:id', { id: '@id' }, {
            //...
            'getLicenseTypes': { method: 'GET', url: 'api/licenses/types', isArray: true }
        });
    });

The result of the GET request is:

["Trial","Standard"]

But using the resource in a controller:

$scope.licenseTypes = License.getLicenseTypes()

i get the following result:

licenseTypes: 
[ undefined, { 
0: S
1: t
2: a
3: n
4: d
5: a
6: r
7: d
 } ]

I'm using AngularJS 1.1.4 with Chrome.

Whats wrong with my resource definition?

dna
  • 1,498
  • 1
  • 14
  • 35
  • 1
    Duplicate of: http://stackoverflow.com/questions/13813673/one-dimensional-array-of-strings-being-parsed-to-2d-by-angular-resource?rq=1 – Intelekshual May 02 '13 at 17:18

1 Answers1

4

There is really not much point in using $resource for data structures like those. The thing is that $resource works great for RESTful endpoint where all the HTTP verbs are used. To make this easy AngualarJS extends incoming objects with convenience methods ($save, $delete etc.). If you return primitives there is no room for extension and one of the major benefits of $resource is gone.

In short: if you are just after fetching data $resource is an overkill IMO, stick with the $http instead.

pkozlowski.opensource
  • 117,202
  • 60
  • 326
  • 286