繁体   English   中英

如何使复选框默认为默认?

[英]How to make a checkbox selected default?

<span ng-repeat="location in model.locations ">
    <input type="checkbox" ng-disabled="isDisabled" ng-model="locations.isChecked" ng-true-value="CHECKED" ng-false-value="UNCHECKED" ng-change="filterGrid(location)">
    <label>{{ location }}</label>
</span>

列表格式的数据i

0: "One"
1: "Two"
2: "Three"
3: "USA"
4: "India"
5: "Japan"
6: "China"



 $scope.model.locations = data.location;
    for(var i=0;i<$scope.model.locations.length;i++){
         if($scope.model.locations[i] == 'USA'){
        $scope.model.locations[i].isChecked ="CHECKED"
        }
    }

但是我无法将USA设为默认值,可能是因为它是字符串格式。

请建议

我相信你可以使用ng-checkedng-checked Angularjs文档

我尝试它,默认情况下有它,这里是我的代码:

main.js

  $scope.locations = [
{ name : "One"},
{ name : "Two"},
{ name : "Three"},
{ name : "USA"},
{ name : "India"},
{ name : "Japan"},
{ name : "China"} ];

main.html中

<span ng-repeat="location in locations">
  <input type="checkbox" ng-checked="location.name == 'USA'">
  <label>{{ location.name }}</label>
</span>

希望对您有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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