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' }
}
);