Ng-checked doesn't work angular for checkbox

I've tried to use a checkbox and bind the checked attribute using the ng-checked attribute, but doesn't work where its working fine with the ng-model attribute with checkbox type inputs.

<!-- not working -->
<input type="checkbox" name="checkedBox"
                       id="checkedBox11"
                       ng-checked="isChecked">

<!--working-->
<input type="checkbox" name="checkedBox"
                       id="checkedBox21"
                       ng-model="isChecked">

      

I created a jsbin to demonstrate the same: here

+3


source to share


2 answers


Since you don't connect the checkbox to the model in the first case, it doesn't change in angular and hence the value doesn't change in the view either.

However, in the second case, you bound the isChecked checkbox to the checkbox, the changes are reflected.



Update. If you change the default isChecked to true, it will display true and the checkbox will also be checked on load.

+4


source


Changing the first entry to the model, changing it. You can also use ng-click to change the value. ( addming ng-model="isChecked"

)

<input ng-model="isChecked" type="checkbox" name="checkedBox" id="checkedBox11" ng-checked="isChecked"> 

      



Or you can add ng-click="isChecked=!isChecked"

checkbox

+1


source







All Articles