var drinksApp = angular.module('drinksApp',[]);
drinksApp.controller('drinkListController',
function drinkListController($scope) {
$scope.drinks = [];
$scope.toggleActive = function(d){
d.active = !d.active;
calculateTotal();
};
$scope.money = 0;
$scope.calculateTotal = function() {
money = 0; //Обнулим предыдущее значение
angular.forEach($scope.drinks, function(d){
money = money + d.price;
}
};
});
});
var drinksApp = angular.module('drinksApp',[]);
drinksApp.controller('drinkListController',
function drinkListController($scope) {
$scope.drinks = [];
$scope.toggleActive = function(d){
d.active = !d.active;
};
$scope.money = 0;
$scope.$watch('d.active', function (newValue, oldValue) {
if (newValue != oldValue && newValue){
money = 0; //Обнулим предыдущее значение
angular.forEach($scope.drinks, function(d){
money = money + d.price;
}
});
});
});
<h3>Total: <span>{{money}}</span></h3>