2017-04-19 9 views
0

私はこの問題を解決するために過去2時間を探しています。解決するための簡単な答えが見つかりません。チェックボックスがオンになっているかどうかを知る方法?

チェックボックスがオンになっているかどうかをチェックしたいのですが、コンソールでは常にチェックが外されています。

HTML:

<ion-checkbox ng-model="option1" ng-true-value="2" ng-false-value="0" id="itemOrder-checkbox1">With option 1 (+$2)</ion-checkbox> 
     <ion-checkbox ng-model="option2" ng-true-value="3" ng-false-value="0" id="itemOrder-checkbox2">With option 2 (+$3)</ion-checkbox> 
     <ion-checkbox ng-model="option3" ng-true-value="1" ng-false-value="0" id="itemOrder-checkbox3">With option 3 (+$1)</ion-checkbox> 
     <label class="item item-input" id="itemOrder-input4"> 
     <input id="notes" type="text" placeholder="Add some notes..."> 
     </label> 
     <div class="spacer" style="width: 300px; height: 33px;"></div> 
     <button class="button button-block button-dark" style="color:#F5E124;" type="submit" id="itemOrder-button3" ng-click="addToCart()"> 
      Add to cart (${{quantity * (15 + option1 + option2 + option3)}}) 
     </button> 

コントローラー:

$scope.addToCart = function(){ 
    if ($scope.option1) { 
     console.log("CheckBox is checked."); 
    } else { 
     console.log("CheckBox is not checked."); 
    } 

    firebase.database().ref('accounts/' + userId + '/cart/').push({ 
     item: "item1", 
     quantity: document.getElementById('quantity').value, 
     price: document.getElementById('price').textContent, 
     notes: document.getElementById('notes').value, 

    }) 
    $state.go("menu2.menu"); 
    } 
+0

利用ngの変更を試してみて、 – Sajeetharan

+0

こんにちは、私はこれに新しいです更新、私はどのように行うには考えていますそう。 – FrenchyNYC

+0

あなたの前の質問に示したデモを確認してください。答えがあります – Sajeetharan

答えて

0

コントローラー:ここ

$scope.click = function(){ 
    if ($scope.option1) { 
     alert("CheckBox is checked."); 
    } else { 
     alert("CheckBox is not checked."); 
    } 
    } 

はデモです:Plnkr

1

<html> 
 
<head> 
 
    <title></title> 
 
</head> 
 
<body> 
 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script> 
 
    <script type="text/javascript"> 
 
     var app = angular.module('MyApp', []) 
 
     app.controller('MyController', function ($scope, $window) { 
 
      $scope.CheckPassport = function() { 
 
       if ($scope.HasPassport) { 
 
        $window.alert("CheckBox is checked."); 
 
       } else { 
 
        $window.alert("CheckBox is not checked."); 
 
       } 
 
      }; 
 
     }); 
 
    </script> 
 
    <div ng-app="MyApp" ng-controller="MyController"> 
 
     Do you have Passport? 
 
     <label for="chkPassport"> 
 
      <input id="chkPassport" type="checkbox" ng-model="HasPassport" /> 
 
     </label> 
 
     <input type="button" value = "Check Passport" ng-click = "CheckPassport()" /> 
 
    </div> 
 
</body> 
 
</html>

0

チェックボックスのためng-checkedディレクティブを使用してください。

あなたは私のこのためのコードを記述してくださいすることができ、この

<html> 
 
<head> 
 
    <script Src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.js"></script> 
 

 
    <script> 
 
     var app=angular.module("myapp", []); 
 
     app.controller("namesctrl", function($scope){ 
 
      $scope.isChecked = true; 
 
     }); 
 

 
    </script> 
 
</head> 
 
<body ng-app="myapp" ng-controller="namesctrl"> 
 
    {{isChecked}} 
 
    <input ng-model="isChecked" type="checkbox" ng-checked="isChecked"><label>Check Box Label</label> 
 
</body> 
 
</html>

関連する問題