我有一个简单的表格,其中的数据总结了按下的项目(通过添加)
(JSBIN)

(700 = 300 + 400)
表格受限于 ng-controller="OrderFormController"
这个方法有哪些内容:
$scope.total = function(){
var total = 0;
angular.forEach($scope.services, function(s){
if (s.active){
total+= s.price;
}
});
return total;
};
Run Code Online (Sandbox Code Playgroud)
一切都好.
但如果图片看顶部,有一个复选框.
当它被检查时,我想在里面做完全不同的计算$scope.total
让我们说,而不是添加 - 做乘法:
$scope.total = function(){
var total = 1;
angular.forEach($scope.services, function(s){
if (s.active){
total*= s.price;
}
});
return total;
};
Run Code Online (Sandbox Code Playgroud)
当然我可以检查方法内部是否选中了复选框,但我不想这样做.
题
将它绑定到不同方法(根据/ )的正确方法(我是angularjs初学者)是什么?checkedunchecked