<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设为默认值,可能是因为这是字符串格式。
请建议
答案 0 :(得分:1)
我相信你可以使用ng-checked
:
Angularjs doc on ng-checked
我尝试了,我默认拥有它,这里是我的代码:
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>
我希望它会有所帮助。