2016-01-29 69 views
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> 

它有两个字符串值true和false。我给作为值=“假”,但复选框没有得到检查,这里的语言是一个列表。复选框未检查角度js

+0

这里语言是列表 – smith

回答

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> 

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

0

如果您希望默认选中该复选框,请使用checked=""checked="checked"

请访问以下链接了解更多详情。

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> 
+0

我给语言.speak,阅读,写作字符串不布尔 – smith

+1

,我已经试过这个,但没有工作 – smith

+0

你做错了什么,否则它总是工作,使复选框检查。 –

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

in controller 

$scope.check = true; 
1

属性的值是不是真正使用。 Angular使用模型值来设置检查。有时您可能需要声明真/假标准。您可以用NG-初始化指令initalize像这样:

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

请注意,您必须单引号真/假值,因为NG预计的表达中。