私はすべてのdetalle.price
要素の合計の最終数を得るためにこのコードを作ろうとしています。彼らはすべて数字なので、私はそれらを合計し、sum()
に最終番号を掲示する必要があります。AngularJSで合計金額を計算してください
<div id="pedidos_table">
<div id="pedidos_table_item" ng-repeat="detalle in detalles">
<p id="pedidos_table_item_name">{{detalle.name}}</p>
<p id="pedidos_table_item_price">{{detalle.price}}$</p>
</div>
</div>
<div id="pedidos_table_total">
<p id="pedidos_table_item_name">TOTAL</p>
<p id="pedidos_table_item_price">{{sum()}}$</p>
</div>
私はこれをやって試してみた:
$scope.sum = function(){
var total = 0;
total += detalle.price;
return total
}
私が欠けている何かがあると知っているが、私は何を知りません。
があなたのJSONファイルを投稿し、あります。 –
[AngularJS ng-repeatの反復要素の合計を計算する]の可能な複製(http://stackoverflow.com/questions/22731145/calculating-sum-of-repeated-elements-in-angularjs-ng-repeat) – Phil