I would like to know if it's possible to use while
or for
with a nested call to $http.get
:
This is an example:
for (var i = 0; i < $scope.comments.length; i++) {
alert($scope.comments[i].id); // = 2
$http.get('/api/logged/like/isliked?id=' + $scope.comments[i].id).success(function(data, status, header, config) {
alert('Test');
alert($scope.comments[i].id); // Not executed.
}).error(function(data){alert('The requeste isn't working');}); }
I put two alert
s to display the id of my comment I'm using to retrieve JSON. I get the id with the first alert, then 'Test' for the second, but the third alert isn't displaying. Why not?
Here an example of the JSON:
{data":[
{"id":2,"is_liked":false,"nb_comments":1,"nb_likes":1,
"date_creation":"2014-05-26T17:03:54+0000"},
{"id":1,"is_liked":true,"nb_comments":0,"nb_likes":1,
"date_creation":"2014-05-26T17:00:26+0000"}
]}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…