0
Я создаю динамический список форм, а в строке есть значение промежуточного итога, и мне нужно иметь общую сумму. Но моя проблема в том, что я не могу суммировать все значения.Как суммировать все значения массива с помощью Angular
Вот немного моего кода:
//i created a array that will hold all subtotals
$scope.grand_total = [];
//this function is visible in every row
$scope.subTotal = function($index) {
var total = 0;
angular.forEach($scope.quoteHeader.items[$index], function(value){
angular.forEach(value.items, function(v) {
total += v.unit * v.unit_price;
$scope.grand_total.push({
subtotal: total
});
});
});
return total;
}
//this will process the sum but It didn't work
function computeGrandTotal() {
var total = 0;
angular.forEach($scope.grand_total, function(value) {
console.log(value);
});
}
$scope.grandTotal = function() {
var total = 0.00;
computeGrandTotal(); //call the subtotal function
console.log(computeGrandTotal());
return total;
}
Вот plnkr: http://plnkr.co/edit/Bfd1e5?p=preview
Я надеюсь, что вы можете помочь мне с этим. Вот все благодарности :)
http://plnkr.co/edit/YSq8VFSg1aOBYePhRLRu?p= Предварительный просмотр –
Спасибо за очень хороший ответ. :) Теперь работает :) – Jerielle