rahul aggarwal rahul aggarwal - 4 months ago 12
AngularJS Question

Binding Checkbox based on the value of the field in AngularJS

I want to check/uncheck checkbox based on the value of the field

services.Register.IsTest
.

When services.Register.IsTest=True
My checkbox should be checked else not

my checkbox

<input type="checkbox" id="patReturned" value="Returned">


I am new to AngularJS. Please help.

Thanks

Answer

Your are looking for the ngChecked directive from AngularJS

Sets the checked attribute on the element, if the expression inside ngChecked is truthy.

Use it like this

<input type="checkbox" id="patReturned" value="Returned" ng-checked="services.Register.IsTest">