Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sound like <code>$scope.ServiceResult</code> return promise and you run <code>forEach</code> before, actually, got data. The other problem should be that <code>query()</code> method returns nothing at all.</p> <p>So we will try both options:</p> <p><strong>If <code>$resource('/CIS/webresources/service/')</code> is async:</strong></p> <p>Try to change your factory and call method like: </p> <pre><code>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; }]); </code></pre> <p>And call it in controller:</p> <pre><code> Services.query() // query() returns promise .then(function (result) { angular.forEach(result, function(eachService) { console.log(eachService.id); }); }, function (result) { alert("Error: No data returned"); }); </code></pre> <p>A <strong>promise</strong> 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.</p> <p>Here is Demo in <kbd><a href="http://jsfiddle.net/9Ymvt/542/" rel="nofollow">Fiddle</a></kbd> that can help you</p> <p><strong>If <code>$resource('/CIS/webresources/service/')</code> is not async:</strong></p> <pre><code>CIS.factory('Services', ['$resource','$q', function($resource, $q) { var data = $resource('/CIS/webresources/service/'); var factory = { query: function () { return data; } } return factory; }]); </code></pre> <p>And controller (like yours):</p> <pre><code>$scope.ServiceResult = Services.query(); $scope.getIds = function() { angular.forEach($scope.ServiceResult, function(eachService) { console.log(eachService.id); }); }; </code></pre> <p>relevant Example: <kbd><a href="http://jsfiddle.net/9Ymvt/626/" rel="nofollow">Fiddle</a></kbd></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload