angularjs - Trying to sum up a number field in ng-repeat -
i'm tying sum number field display total in angularjs project.
i'm trying this:
<div ng-repeat="item in donations"> {{item.product.cost * (item.product.donation/100)}} //result amount donated based on 'donation' </div> so above expression pull donated portion of cost. need able sum number show total donation.
any ideas?
thanks!
edit: working plunker - https://embed.plnkr.co/psoeqo/
the best way create <div> display total.
if you, create $scope.donations.total inside controller , display inside new <div>.
controller:
$scope.donations.total = $scope.donations.reduce(function( prevval, elem ) { return prevval + (elem.cost * (elem.donation/100)); }, 0); html:
<div ng-repeat="item in donations"> {{ item.product.cost * (item.product.donation/100) }} </div> <div>{{ donations.total }}</div>
Comments
Post a Comment