admin管理员组文章数量:1355522
On page load i am checking if attestationStatus flag is approved i want to make check box checked , with below implementation its not working, Any idea what implemented wrong.
main.html
<div class="col-md-3">
<label class="radio-inline">
<input type="checkbox"
ng-model="aprv"
name="attestorFlag"
id="attestorFlag"
ng-value="'Y'"> I attest
</label>
</div>
main.js
if ($scope.attestorObj.attestationStatus === 'approved') {
$scope.aprv = 'Y';
}
On page load i am checking if attestationStatus flag is approved i want to make check box checked , with below implementation its not working, Any idea what implemented wrong.
main.html
<div class="col-md-3">
<label class="radio-inline">
<input type="checkbox"
ng-model="aprv"
name="attestorFlag"
id="attestorFlag"
ng-value="'Y'"> I attest
</label>
</div>
main.js
if ($scope.attestorObj.attestationStatus === 'approved') {
$scope.aprv = 'Y';
}
Share
Improve this question
edited Jul 6, 2015 at 21:52
Luke Merrett
5,82410 gold badges41 silver badges70 bronze badges
asked Jul 6, 2015 at 21:46
aftabaftab
5454 gold badges14 silver badges46 bronze badges
1
- Maybe remove one of the equal signs in your if statement? Unless your checking identity as well – code Commented Jul 6, 2015 at 21:51
2 Answers
Reset to default 5You don't need ng-value
. Use only ng-model
and set the $scope.aprv
value to true
or false
.
<input type="checkbox" ng-model="aprv" name="attestorFlag" id="attestorFlag">
Controller:
if ($scope.attestorObj.attestationStatus === 'approved') {
$scope.aprv = true;
}
http://codepen.io/ces/pen/gpexBX
you could add the condition to your checkbox itself by adding the ng-checked. think this should work for you, hope this helps or gets you in the right direction
<div class="col-md-3">
<label class="radio-inline">
<input type="checkbox"
ng-checked="$scope.attestorObj.attestationStatus == 'approved'"
ng-model="aprv"
name="attestorFlag" id="attestorFlag"> I attest </label>
</div>
本文标签: javascriptHow to make checkbox checked if condition is trueStack Overflow
版权声明:本文标题:javascript - How to make checkbox checked if condition is true? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744017538a2576609.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论