0
<tr ng-repeat="languages in samln">
   <td>
      <span>{{languages.emplang}}</span>
   </td>
   <td>
      <input type="checkbox" name="checkbox1-" id="sp1" value="false" style="margin-left:40px;" ng-model="languages.speak">
   </td>
   <td>
      <input type="checkbox" name="checkbox2-" id="rea1" value="false" style="margin-left:40px;" ng-model="languages.read">
   </td>
   <td>
      <input type="checkbox" name="checkbox3-" id= "wr1" value="false" style="margin-left:40px;" ng-model="languages.write">
   </td>
</tr>

It has two string values true and false. I gave as value="false" but checkbox is not getting checked and Here languages is a list.

1
  • Here languages is a list Commented Jan 29, 2016 at 11:09

4 Answers 4

1
<input type="checkbox" name="" value="" ng-checked="check" />

in controller 

$scope.check = true;
Sign up to request clarification or add additional context in comments.

Comments

1

The value attribute isn't really used. Angular uses the model value to set the check. Sometimes you may need to declare the true / false criteria too. You can initalize with the ng-init directive like so:

<input type="checkbox" name="checkbox1" id="sp1" 
     ng-true-value="'true'" ng-false-value="'false'"    
     ng-init="test='true'" ng-model="test">

Note that you have to single quote the true / false values since ng expects an expression there.

Comments

0
<script>
  angular.module('checkboxExample', [])
    .controller('ExampleController', ['$scope', function($scope) {
      $scope.checkboxModel = {
       value1 : true,
       value2 : 'YES'
     };
    }]);
</script>
<form name="myForm" ng-controller="ExampleController">
  <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/>
 </form>

Source: AngularJS documentation / API Reference / ng / input components in ng / input[checkbox]

Comments

0

If you want the check-box to be checked by default then use checked="" or checked="checked".

Please visit below link for more details.

https://www.w3.org/TR/html-markup/input.checkbox.html

   <tr ng-repeat="languages in samln">
       <td>
          <span>{{languages.emplang}}</span>
       </td>
       <td>
          <input type="checkbox" name="checkbox1-" id="sp1" checked="" style="margin-left:40px;" ng-model="languages.speak">
       </td>
       <td>
          <input type="checkbox" name="checkbox2-" id="rea1" checked="" style="margin-left:40px;" ng-model="languages.read">
       </td>
       <td>
          <input type="checkbox" name="checkbox3-" id= "wr1" checked="" style="margin-left:40px;" ng-model="languages.write">
       </td>
    </tr>

2 Comments

I am giving the languages.speak, read ,write as strings not boolean
You have done something wrong otherwise it always works to make check-box checked.

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.