I have the following code with Angular.js:
$scope.createSSH = function(){
for (var j=0; j<allGroupsArrays.length; j++){
for (var i=0; i<$scope.appArray.length; i++){
allGroupsArrays[j][i][6] = Boolean(0);
allGroupsArrays[j][i][7] = Boolean(0);
// Some irrelvant code
WClient.createSSHK(allGroupsArrays[j][i][2], allGroupsArrays[j][i][3], allGroupsArrays[j][i][4], i, allGroupsArrays[j], allGroupsArrays[j][i][7], j).then(
function(data) {
console.log("The j is: " + j)
console.log("The i is: " + i)
},
function(message) {
console.log("Error")
}
When the callback is backed, I notice that j
and i
variables value were note save. Instead, It prints the following:
The j is: 5
The i is: 3
These even when the callback was executed were i
was 0 and j
was 0.
How can I save the variable's values context?