Encountering an issue with Angular $resource: error description
Error: error:badcfg
Response does not match configured parameter:
Error in resource configuration for action `array`. Expected response to contain an object but got an {2}
Initialization of ng app is as follows:
var appRoot = angular.module('smapp', ['ngRoute', 'ui.bootstrap', 'ngResource']);
The service:
appRoot.factory('ProgramsResource', function ($resource) {
return $resource('Home/Program', {}, { Program: { method: 'get', isArray: false } })
});
Within the controller:
appRoot.controller('ProgramCtrl', function ($scope, ProgramsResource) {
$scope.searchPrograms = function () {
$scope.Programs = ProgramsResource.query(
{
TotalItems: $scope.TotalItems,
ItemsPerPage: $scope.ItemsPerPage,
PageNo: $scope.CurrentPage
});
};
$scope.TotalItems = 175;
$scope.ItemsPerPage = 20;
$scope.CurrentPage = 1;
$scope.searchPrograms();
});
Json response from the server:
{"TotalItems":175,"ItemsPerPage":20,"PageNo":5,"List":[{"Code":"MATH2014","Name":"Name1","Tags":"Tag1,Tag2"},{"Code":"MATH2015","Name":"Name2","Tags":"Tag1,Tag2"}]}
Error is triggered by the above JSON structure
To resolve the error, when sending a simpler JSON without "List", it works fine:
[{"TotalItems":0,"ItemsPerPage":0,"PageNo":0},{"TotalItems":0,"ItemsPerPage":0,"PageNo":0}}]
Being new to Angular, unsure about the mistake being made.