I am getting question list from server with get request. Some of questions are unread and their attribute is
"okundu":"0";
I want to change it to
"okundu":"1";
In my code below I get questions from service and try to put request in loop. But it doesn't work due to async problem. I am new in angular.js .How can I solve this problem ?
$http.get('http://example/sorus?userId='+sessionStorage.refUser).success(function(response){
sorus=response;
for(var i=0;i<sorus.length;i++){
if(sorus[i].okundu=="0"){
console.log(sorus[i]._id)
$http.put('http://example/sorus/'+sorus[i]._id,{"okundu":"1"}).success(function(response){console.log(response)}).error(function(err){console.log("ERR : " + err)})
}
}
})
in put request it always goes to error function and err returns null.If I write console.log above of put request I see that result is
59817b57a720c13e31d3def4
59817b46a720c13e31d3def3
ERR : null
ERR : null
There is async problem here. It never enters success of put request. It goes to error of put request.