Having trouble retrieving an array using $resource
. Can anyone assist me with this? It works fine when I use $http
Encountering an error in the console:
TypeError: undefined is not a function
at http://127.0.0.1:9000/bower_components/angular-resource/angular-resource.js:597:29
at forEach (http://127.0.0.1:9000/bower_components/angular/angular.js:327:18)
at angular.module.provider.$get.Resource.(anonymous function).$http.then.value.$resolved (http://127.0.0.1:9000/bower_components/angular-resource/angular-resource.js:595:19)
at deferred.promise.then.wrappedCallback (http://127.0.0.1:9000/bower_components/angular/angular.js:11616:81)
at http://127.0.0.1:9000/bower_components/angular/angular.js:11702:26
at Scope.$get.Scope.$eval (http://127.0.0.1:9000/bower_components/angular/angular.js:12797:28)
at Scope.$get.Scope.$digest (http://127.0.0.1:9000/bower_components/angular/angular.js:12609:31)
at Scope.$get.Scope.$apply (http://127.0.0.1:9000/bower_components/angular/angular.js:12901:24)
at done (http://127.0.0.1:9000/bower_components/angular/angular.js:8487:45)
at completeRequest (http://127.0.0.1:9000/bower_components/angular/angular.js:8703:7)
A factory was created with the following method
coeffsResource.factory("CoeffsResources",['$resource',
function($resource) {
return $resource('/api/:action',{}, {
get_all_coeffs: { method:'GET', isArray:false, params: {action: 'getAllRegionCoefficients'} },
save_all_coeffs: { method:'POST', params: {action: 'storeAllRegionCoefficients'} },
get_manufacturer: { method: 'GET', isArray:true, params: {action: 'getAllManufacturers'} },
get_models: { method: 'GET', params: {action: 'getModels'} },
get_classes: {method: 'GET', params: {action: 'getClassesConfig'} },
get_regions: {method: 'GET', params: {action: 'getAllRegions'} },
get_ages_config: {method: 'GET', params: {action: 'getAgesConfig'} },
get_odometer: {method: 'GET', params: {action: 'getOdometersConfig'} },
get_tax_config: {method: 'GET', params: {action: 'getTaxConfig'} }
}, {stripTrailingSlashes: false})
}]);
Integrating the factory into the controller
angular.module('etachkaEvaluatorFrontendApp')
.controller('CoeffCtrl', function($scope, $http, $resource, $q, CoeffsResources) {
var coeffsResourcesObject = new CoeffsResources();
coeffsResourcesObject.$get_manufacturer().then(function() {
}, function() {
})
})