I'm trying to add a checkbox to select/deselect all the item then sum all the item. I have done some code for it. however, both function is separate now and I would like to merge it together to achieve the target.
HTML
//Select all checkbox
<input type="checkbox" ng-change="checkAll()" ng-model="params.checkbox[0]"
class="ng-valid ng-dirty ng-valid-parse ng-touched ng-empty" style="">
//Select a single checkout and do cal balance
<input type="checkbox" name="marked_reconciled" ng-
model="trx.marked_reconciled" ng-change="calBalance()">
This is AngularJs
$scope.checkAll = function () { angular.forEach($scope.records, function (v)
{ $scope.params.checkbox[v.id] = $scope.params.checkbox[0]; }); };
$scope.calBalance = function () {
if (!$scope.trans) {
return;
}
var current = 0;
var statement_mth = new Date($scope.item.reconcile_date).getMonth();
angular.forEach($scope.trans.trans, function (trx) {
var reconcile_mth = new Date(trx.reconcile_on).getMonth();
if (trx.marked_reconciled && ((statement_mth == reconcile_mth) || !trx.reconcile_on)) {
if (trx.entry == 'debit') {
current += parseFloat(trx.amount);
} else if (trx.entry == 'credit') {
current -= parseFloat(trx.amount);
}
}
});
};
I have tried to merge the ng-change as "checkAll();calBalance()" but doesn't work.
Aucun commentaire:
Enregistrer un commentaire