如何通过默认设置真实复选框
问题描述:
HTML:如何通过默认设置真实复选框
<div class="col-lg-2 col-sm-2 col-md-2 col-xs-2">
<input type="checkbox" ng-model="selectedRecord.extendLiveData" >
</div>
JS:
$scope.selectedRecord.extendLiveData = true;
想默认为true设置复选框。怎么样 ?没有ng-checked
,ng-change
答
与真实值extendLiveData
场创建selectedRecord
对象。
var app = angular.module('myApp', []);
app.controller('chkboxCtrl', function($scope, $http) {
$scope.selectedRecord = {extendLiveData: true}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="chkboxCtrl">
<div class="col-lg-offset-2 col-lg-10">
<div class="checkbox c-checkbox">
<label>
<input type="checkbox" ng-model="selectedRecord.extendLiveData">
<span class="fa fa-check"></span> checkbox checked by default
</label>
</div>
</div>
</div>
答
你可以做到这一点通过HTML这样:
<input type="checkbox" ng-model="selectedRecord.extendLiveData" checked>
答
只是初始化$scope.selectedRecord
为对象
$scope.selectedRecord = {};
$scope.selectedRecord.extendLiveData = true;
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.selectedRecord = {};
$scope.selectedRecord.extendLiveData = true;
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<div class="col-lg-2 col-sm-2 col-md-2 col-xs-2">
<input type="checkbox" ng-model="selectedRecord.extendLiveData" > box value {{selectedRecord.extendLiveData}}
</div>
</div>
+0
@ SACHILA我做了同样的事,但没有工作 –
答
只要把“车cked“在输入标签中。像:
<input type="checkbox" ng-model="selectedRecord.extendLiveData" checked>
是内部的NG-重复你的复选框? – Vivz