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

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -