How can i store angular.forEach result to each table row? I tried to pupulate my table using ng-repeat, but somehow angular-foreach overrides the table row for every loop.
Can someone help me.
Here's a sample of my code
$scope.getProfile= function(){
$http({
method: 'post',
url: 'url',
data: some_param,
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
}).then(function(result) {
$scope.name= result.data.name;
angular.forEach($scope.name,$scope.getFamily);
});
}
result = {"name":[{"mom_name":"Jane","child_name":["Joey","Jade","Joe","Jenny"],"child_count":4},{"mom_name":"Diane","child_name":["Donny","Daisy","Diana","Douglas","Damon"],"child_count":5},{"mom_name":"Anna","child_name":["Arthur","Amanda","Amon"],"child_count":3}]}
sample for the first forEach loop with mom_name = "Jane"
$scope.getFamily = function(name) {
var child_name= name.child_name;
var mom_name= name.mom_name;
$http({
method: 'post',
url: 'url',
data: some_param
})),
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
}).then(function(result) {
var name_data = result.data;
//get gender count
var total = { mom: mom_name, male: 0, female: 0, female_name: []};
for(var i = 0; i < name_data.length; i ) {
if(name_data[i]['gender'] == 'male'){
total['male'] ;
}
}
for(var i = 0; i < name_data.length; i ) {
if(name_data[i]['gender'] == 'female'){
total['female'] ;
total['female_name'].push(name_data[i]['child_name']);
}
}
$scope.getChildAge(total);
});
}
result = [{"child_name":"Joey","gender":"female"},{"child_name":"Jade","gender":"female"},{"child_name":"Jonny","gender":"male"},{"child_name":"John","gender":"male"}]
total = {mom: 'Jane', male: 1, female: 2, female_name: ["Joey","Jade","Jenny"]}
$scope.getChildAge= function(data) {
var mom= data.mom;
var female_total= data.female;
var female_name= data.female_name;
$http({
method: 'post',
url: 'url',
data:
data: some_param,
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
}).then(function(result) {
var child_age = result.data;
var count_num = 0;
for(var i = 0; i < child_age.length; i ) {
if(children[i] > 5){
count_num ;
}
}
console.log(count_num);
});
}
I want my output table to be like this
CodePudding user response:
I worked my way in getting my desired output
I declare this outside getFamily() function
$scope.gender_summary = [];
and add this line inside the getFamily()
$scope.gender_summary.push(total);
then i use the ng-repeat $scope.gender_summary in my table.