1

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 ..

3
  • When you are logging $scope.add_product? Commented Feb 4, 2017 at 5:44
  • 'app.controller('add_product_ctrl', ['$scope', '$http', function($scope, $http) { $scope.addProfileDetail = function(file) { //HERE console.log($scope.console.log($scope.add_product)) } }])' Commented Feb 4, 2017 at 5:48
  • Check my answer below for working with checkboxes or post a minimal working version in plnkr, jsbin.. Commented Feb 4, 2017 at 5:49

1 Answer 1

2

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>

Sign up to request clarification or add additional context in comments.

1 Comment

@Elamparithi.P I'm glad it helped. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.