I have simple function in scope which calls some service several times. I want to append retrieved data to the array in the scope.
$scope.foo = function(){
$scope.someArray = [];
for(var i = 0; i < something.length; i++){
var name = something[i];
FooService.someMethod($resource, name).then(function (result) {
if(result){
$scope.someArray.push(name);
}
}
}
}
The problem is someArray
in a result is filled with set of the same values. It's the last pushed value repeated something.length
times.
How should I handle scope objects if I want to modify them from callbacks?