I'm learning AngularJS and now I want to know how to make the average of the checked values for the value entity, please teach/show me how.
Here you have a plunker w/ my code:
https://plnkr.co/edit/iBdEtQU1gPrCSxXQ2yyW?p=preview
And for those one who don't want to enter the link.
View HTML:
<table style="border: 1px solid black">
<thead>
<tr>
<th></th>
<th>Id</th>
<th>Name</th>
<th>Address</th>
<th>Value</th>
</tr>
<td><b>Total</b></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tbody ng-repeat= "values in getSelected()">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tbody>
</thead>
</table>
</div>
<p>Average: </p>
</body>
Controller code:
$scope.getSelected = function () {
var ar = $scope.employees.filter(
function (value) {
if (value.checked == 1) {
return true;
} else {
return false;
}
}
);
console.log(ar);
return ar;
};
$scope.getSum = function() {
return $scope.getSelected().reduce((sum, item) => {
return (sum + item.value);
}, 0);
}
$scope.getAverage=function(){
}
Aucun commentaire:
Enregistrer un commentaire