I have a simple form with data which summarize the pressed items ( via addition)
(JSBIN)
(700=300+400)
The form is bounded with ng-controller=OrderFormController
Which inturn has this method :
$scope.total = function(){
var total = 0;
angular.forEach($scope.services, function(s){
if (s.active){
total+= s.price;
}
});
return total;
};
All ok.
But look at the top if the picture , there is a check box.
When it's checked , I want to do totally different calculation inside $scope.total
Let's say , instead of addition - do multiplication :
$scope.total = function(){
var total = 1;
angular.forEach($scope.services, function(s){
if (s.active){
total*= s.price;
}
});
return total;
};
Of course I could check inside the method whether the checkbox is checked , but I don't want to do that.
Question
What is the right way ( i'm angularjs beginner) of bounding it to a different method (according to checked
/unchecked
)?