Answer the question
In order to leave comments, you need to log in
How to calculate ng-model sum?
Guys, I don’t understand what my mistake is, I can’t calculate the sum in the right column of all screencast.com/t/fwBwmo9S2f items .
Working site angular.andriyboyko.com
$scope.total = function() {
var total = 0;
angular.forEach($scope.newArray.items, function(item) {
total += item.totalItem;
})
return total;
}
Answer the question
In order to leave comments, you need to log in
So in theory it’s true if you need to count the number of kcal)
var appElement = document.querySelector('[ng-controller=SearchCtrl]');
var $scope = angular.element(appElement).scope();
$scope.total = function() {
var total = 0;
angular.forEach($scope.newArray, function(item) {
total += item.kkal;
})
return total;
}
$scope.total(); //answer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question