0
var promise = GetQuestions.quote.get();
console.log(promise);
promise.$promise.then(function(quote) {
  $scope.quotes = quote;
  console.log($scope.quotes);
  for( quote in $scope.quotes){
     console.log(quote.cite);
  }
});

factory

.factory('GetQuestions', ['$resource', function($resource){
   return {
      quote: $resource('**Resource Link**', {}, { get: { method: 'GET', isArray: true }})
   };
}])

Here is console.log(promise):

[$promise: Promise, $resolved: false]

Here is console.log($scope.quotes): enter image description here

And console.log(quote.cite) logs undefined

The Issue:

My issue is that I can't access the "cites", the promise is supposedly resolved however I can't seem to access the data correctly. I have tried doing promise.then() (instead of promise.$promise.then()), however I get an error telling me promise.then() is not a function. I am not sure why this is. Any help?

Pengyy
  • 37,383
  • 15
  • 83
  • 73

1 Answers1

1

Instead of the for var in list syntax, try

$scope.quotes.forEach(function(quote) {
    console.log(quote.cite);
});

The for var in list should not be used to iterate over arrays. It's intended purpose is to iterate over object properties. When you use it to iterate over an array, you will often get weird behavior.

See this SO question.

Community
  • 1
  • 1
gpanders
  • 1,301
  • 2
  • 15
  • 23