W
W
westdp2016-04-04 10:59:19
JavaScript
westdp, 2016-04-04 10:59:19

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;
    }

What's my mistake?
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ruboss, 2016-04-04
@westdp

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 question

Ask a Question

731 491 924 answers to any question