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
Add a ment  | 

2 Answers 2

Reset to default 5

You 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