Ali Nouman
Ali Nouman

Reputation: 3414

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

Hi i am getting this error Error: [$resource:badcfg] Error in resource configuration. Expected response to contain an object but got an array my service code is this

'use strict';

define([
  'angular', 
  'angularResource'
], function (angular) {
    angular.module('myApp.services', ['ngResource'])
        .factory('Pie', function($resource){

            var pieData = $resource('app/api/v1/pie.json');
            return {
                        getPie:function(){
              return pieData.get().$promise;
             }
            }
        });
});

And code in controller is

 Pie.getPie().then(function(result){
            console.log(result);
            });

Upvotes: 0

Views: 1942

Answers (1)

cuttlas
cuttlas

Reputation: 981

If your API returns an array, you have to specify it in the declaration of the resource:

var pieData = $resource('app/api/v1/pie.json', {'get': {method: 'GET', isArray: true}});

Upvotes: 1

Related Questions