I am getting an object in my app by calling a function in service like this:
$scope.quiz= QuizService.fetch($stateParams.quiz).$promise.then(function(result) {
return result;
When I do console.log($scope.quiz) I get this:
Promise {$$state: Object}
$$state:Object
status:1
value:m
$promise:Promise
$resolved:true
active_question_id:1275
code:7690
id:200
mode:"multiplayer"
players:Array[2]
questionCount:7
question_time:10000
status:"active"
subjects:Array[0]
token:"i2L6OLEfAqfD3tLUCMzx"
topics:Array[0]
years:Array[1]
__proto__:Object
__proto__:Object
__proto__:Object
I would like to access object properties years, subjects and topic and loop through them, but when I do console.log($scope.quiz.years) I get
undefined
The service looks like this:
fetch: function(id) {
var result = quizResource.get({id: id});
result.$promise.then(function(quiz) {
service.setCurrent(quiz); });
return result;
},
And the quizResource in QuizService looks like this:
var quizResource = $resource(
AppSettings.apiUrl + '/quizzes/:id/:verb',
{
id: '@id'
},
.then. Its async and the calling code has moved on by the time the promise return is called.quizResource.get()code.