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?

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.