This code works, but I feel like it's really hacky and could be done a lot better. Can anyone give some advice on how this could be neater?
$scope.arrays = function() {
$scope.committees = [];
$scope.employees = [];
$http({method: 'GET', url: 'data.php'}).success(function(data) {
angular.forEach(data, function(value, key) {
$scope.committees.push(value);
})
$http({method: 'GET', url: 'data2.php'}).success(function(data){
angular.forEach(data, function(value, key) {
$scope.employees.push(value);
})
$scope.arr = new Array();
for (var i = 0, committee; committee = $scope.committees[i]; i++) {
for (var j = 0, employee; employee = $scope.employees[j]; j++) {
if (committee.code === employee.code){
$scope.arr.push({
"committee" : committee.name,
"color": committee.color,
"members": committee.members,
"femaleAnnual" : employee.femaleAnnual,
"maleAnnual" : employee.maleAnnual,
"totalAnnual" : employee.totalAnnual,
})
}
}
}
})
})
}
$scope.arrays();
Edit: Sorry I should have been clearer! What I'm trying to do here is merge 2 arrays if they have the same value for 'code' - and then push that array to the scope.