I'm in the process of creating a scoring system and need to calculate a total score based on values from a different set of data. I came across this reference: Calculating sum of repeated elements in AngularJS ng-repeat, but I haven't been successful in making it work for my scenario as it seems to involve only one collection instead of two.
Below is the template I am working with, following the guidance provided in the aforementioned question:
<div>{{parent.id}}</div>
<div>{{ getTotal() }}</div>
<div ng-repeat="child in children | orderBy: '-postedTime' | filter: {parentId: parent.id}">
<div>{{child.score}}</div>
</div>
The corresponding JavaScript code:
$scope.getTotal = function(){
var total = 0;
for(var i = 0; i < $scope.children.length; i++){
var score = $scope.child.score[i];
total += (child.score);
}
return total;
}
Is there a way to sum up all the scores from the filtered children and display the total on the parent element?