简体   繁体   中英

how to get unchecked checkbox value in angularjs?

this is html code

<p>
   <input type="checkbox" ng-model='add_product.kids' class="filled-in" id="filled-in-box1" />
   <label for="filled-in-box1">Kids</label>
</p>

I need to get the value as false when the check box is unchecked ..

I print the model like this

console.log($scope.add_product)

but in that model the checkbox value is not showned ?

Can anybody hepl me ... Thanks in advance ..

You can access checkbox in the following ways

 angular.module("myApp", []).controller("MyController",['$scope', function($scope) { $scope.checkboxModel = { value1 : true, value2 : 'YES' }; }]); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myApp" ng-controller="MyController"> <label>Value1: <input type="checkbox" ng-model="checkboxModel.value1"> </label> <br/> <label>Value2: <input type="checkbox" ng-model="checkboxModel.value2" ng-true-value="'YES'" ng-false-value="'NO'"> </label> <br/> <tt>value1 = {{checkboxModel.value1}}</tt> <br/> <tt>value2 = {{checkboxModel.value2}}</tt> <br/> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM