Sound like $scope.ServiceResult return promise and you run forEach before, actually, got data. The other problem should be that query() method returns nothing at all.
So we will try both options:
If $resource('/CIS/webresources/service/') is async:
Try to change your factory and call method like:
CIS.factory('Services', ['$resource','$q', function($resource, $q) {
var data = $resource('/CIS/webresources/service/');
var factory = {
query: function () {
var deferred = $q.defer();
deferred.resolve(data);
return deferred.promise;
}
}
return factory;
}]);
And call it in controller:
Services.query() // query() returns promise
.then(function (result) {
angular.forEach(result, function(eachService) {
console.log(eachService.id);
});
}, function (result) {
alert("Error: No data returned");
});
A promise represents a future value, usually a future result of an asynchronous operation, and allows us to define what will happen once this value becomes available, or when an error occurs.
Here is Demo in Fiddle that can help you
If $resource('/CIS/webresources/service/') is not async:
CIS.factory('Services', ['$resource','$q', function($resource, $q) {
var data = $resource('/CIS/webresources/service/');
var factory = {
query: function () {
return data;
}
}
return factory;
}]);
And controller (like yours):
$scope.ServiceResult = Services.query();
$scope.getIds = function() {
angular.forEach($scope.ServiceResult, function(eachService) {
console.log(eachService.id);
});
};
relevant Example: Fiddle
$resource('/CIS/webresources/service/')contain?