我正在尝试将变量传递给http请求,但我不能。
代码如下:
for(var i = 1; i <= daysInMonth(); i++){
//Fetch Data
$http.get("urlFromApi/"+i)
.success(function(data){
//Here I can access my data
//BUT I CAN NOT KNOW WHAT THE VALUE OF VARIABLE "i" is.
//BECAUSE success is a callback function it often already has done the loop
//when callback is executed
})
.error(function(er){
console.log("An error occured. Please, try again");
});//end $http get
}//end for loop
问题如下: 我需要将i传递给回调函数,以便在执行回调函数时能够访问它