2017-04-05 39 views
0

因此,我們有一個購物門戶項目,當我們選中該複選框它會加在車中的價值,問題是,當我們取消選中它仍然添加項目的複選框,我們再次對其進行檢查它會再次增加一個值。AngularJS複選框中vlue時選中

picture of adding a other service

 <input type="checkbox" id="{{p.productName}}" ng-checked="defaultCheckState" ng-click="serviceAddOn(p);" /> 

我也試過這個

 <input type="checkbox" id="{{p.productName}}" ng-checked="defaultCheckState" ng-true-value="serviceAddOn(p);" ng-false-value="Clear"/> 

角碼

 $scope.IsSavingAddOn = false; 
    $scope.serviceAddOn = function (product) { 
    $scope.IsSavingAddOn = true; 
    $scope.total = $scope.qty * product.priceValue; 
    //AddToCartService.AddToCart(product.productId, 'Service', $scope.qty, product.priceValue, $scope.total, true); 
    $http.post("/Home/AddCart?productid=" + product.productId + "&subs=Service&qty=" + $scope.qty + "&unitprice=" + product.priceValue + "&amount=" + $scope.total) 
     .then(function (response) { 
     }).finally(function (response) { 
      $scope.$emit('CountCartEvent'); 
      $scope.IsSavingAddOn = false; 
     }); 
}; 

回答

0

使用毫微克的變化和使用,如果條件檢查複選框是否被選中與否

<input type="checkbox" id="{{p.productName}}" ng-checked="defaultCheckState" ng-change="serviceAddOn(p);" /> 

$scope.defaultCheckState = false; 

$scope.serviceAddOn = function (product) { 
    if(defaultCheckState){ 
     $scope.IsSavingAddOn = true; 
     $scope.total = $scope.qty * product.priceValue; 
     //AddToCartService.AddToCart(product.productId, 'Service', $scope.qty, product.priceValue, $scope.total, true); 

     $http.post("/Home/AddCart?productid=" + product.productId + "&subs=Service&qty=" + $scope.qty + "&unitprice=" + product.priceValue + "&amount=" + $scope.total) 
     .then(function (response) { 
     }).finally(function (response) { 
      $scope.$emit('CountCartEvent'); 
      $scope.IsSavingAddOn = false; 
     }); 
    } 
}; 
+0

複選框被禁用我無法檢查它,並且產品名稱變成這樣的代碼{{product.name}} – Woshooo

+0

檢查控制檯是否有任何錯誤 –

+0

錯誤:[$ compile:ctreq] Controller' ngModel」,由指令所要求的‘ngChange’,不能被發現! http://errors.angularjs.org/1.6.3/$compile/ctreq? – Woshooo

相關問題