In the below code,
app.controller('Controller', function($scope, $http){
$scope.rep = [];
$scope.tot = {
name: '',
marketValue: 0,
cash: 0,
legend: 'none'
};
(function loadData(){
$http.get('result.json').
then(function(data) {
angular.forEach(data['data'],function(value, key){
$scope.rep[key] = value;
$scope.rep[key].marketValue = parseFloat(value.marketValue);
$scope.rep[key].cash = parseFloat(value.cash);
});
} ,
function(data) {
console.log("My error: " + data);
}
);
})(); // IIFE
for (var i = 0; i < $scope.rep.length; i++) {
$scope.tot.marketValue += $scope.rep[i].marketValue;
$scope.tot.cash += $scope.rep[i].cash;
}
});
$scope.rep is a local variable that is accessed in nested functions of IIFE.
After IIFE execution, no further execution happens, calm termination of execution.
Console does no give any error message.
Why for-loop does not execute?
asynchronous...and you're hitting your loop before the$httpcall comes back.