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

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -