Say for example I have the following code:
for(var i=0; i < itemlist.length; i++){
var item = itemlist[i];
var id = item.id;
$http.get(id + '.json').success(function(data){
//do something with data.
console.log(item.name);
}
}
The name displayed in the console will be a repeated value (I think the first value in the array itemlist), i.e. the callback function doesn't know about the variable item.
With my level of understanding this is strange. Is there a way to pass in additional variables to this callback function - and/or - could someone enlighten me on why the scope of this variable behaves in this way?