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.

Quite new to angular I'm experimenting with CORS together with AngularJS At this moment I have a service which points to a remote API

angular.module('oc24App')
        .service('Oc24service', function Oc24service() {
            // AngularJS will instantiate a singleton by calling "new" on this function
        }).factory("Products", function($resource) {
    return $resource(
            'http://example.com/api/products/:id',
            {
                'get':    {method:'GET', isArray: false },
                'save':   {method:'POST'},
                'delete': {method:'DELETE'},
                'update': { method:'PUT' }
            }
    );
});

than init from controller

angular.module('oc24App')
  .controller('MainCtrl', function ($scope, Products) {
   Products.query(function(data) {
       Products.get(function(data) {
        $scope.data= data;
        $scope.products= data.data;
        });

    });      
  });

but at this point I get

Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an array but got an object

I rad about that with isArray: false could be fixed and as be shown tried, but not working. How to do this properly?

Update found it

.factory("Products", function($resource) {
        return $resource(
                'http://example.com/api/products/:id',
{}, //paramsDefault place
                {
                    'get':    {method:'GET', isArray: false },
                    'save':   {method:'POST'},
                    'delete': {method:'DELETE'},
                    'update': { method:'PUT' }
                }
        );
share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.