It appears that the question is somewhat unclear, but it seems like this is what you're looking for.
At the start, assign the values of totalPrice
and totalHours
to 0. Use angular.forEach
to loop through each object and add it to the variable.
$scope.calculatePrice = function() {
$scope.totalPrice = 0;
$scope.totalHour = 0;
angular.forEach($scope.options, function(opt) {
$scope.discountList[opt] = {};
$scope.discountList[opt].servers = $scope.servers[opt];
$scope.discountList[opt].subscription = $scope.subs[opt];
var price = (Math.pow($scope.servers[opt], 0.75)) * $scope.priceMapping($scope.subs[opt])[0];
var hours = Math.round((($scope.priceMapping($scope.subs[opt])[1]) * (Math.pow($scope.servers[opt], 0.75))) * 10) / 10;
$scope.discountList[opt].price = price;
$scope.discountList[opt].hours = hours;
$scope.totalPrice += price;
$scope.totalHour += hours
});
console.log("Total Price : ", $scope.totalPrice);
console.log("Total Hours : ", $scope.totalHour);
};
HTML
<div> Total Price : {{totalPrice}}</div>
<div> Total Hours : {{totalHour}}</div>