Angular 5, Typescript 2.7.1
I can't seem to get the checkbox to be checked when returning a boolean, I've tried, item.check
returns either true or false.
<tr class="even" *ngFor="let item of rows"> <input value="{{item.check}}" type="checkbox" checked="item.check">
The checkbox is always checked when checked is written inside input. And it does not get unchecked when checked="false"
.
Is there a better way to do it with Angular features instead? like ngModel or ngIf???
Solution
<input type="checkbox" [checked]="item.check == 'true'">
try:
[checked]="item.checked"
check out: How to Deal with Different Form Controls in Angular
You can use this:
<input type="checkbox" [checked]="record.status" (change)="changeStatus(record.id,$event)">
Here, record is the model for current row and status is boolean value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With