This is my simple code which just adds a question in a database and then get an id as the result and then tries to add questionId
in all answer.questionId
var size = questions.length;
for(var i=0; i<size; i++){
$http.post(url + "questions", questions[i]).success(function(result){
questions[i].answers = questions[i].answers.map(function(answer){
return answer.questionId = result;
});
});
}
But promise calls in the end of the loop, therefore, question[i] - undefined since i = size
;
How to solve the problem ?