DEV Community

John Peters
John Peters

Posted on

Angular Checkbox doesn't check

Try this binding first

   <input 
      #checkbox
      (change)="onCheckBoxChanged(checkbox, setting)"
      [checked]="setting.values[0] != 'false'"       
      type="checkbox"
   />
Enter fullscreen mode Exit fullscreen mode

Where the variable setting is a part of a parent *ngFor loop. This is different than other [(ngModel)] bindings; in that, we are going directly to the input checked attribute. What's interesting is that we had to add the comparator to get it to work.


[checked]="setting.values[0] != 'false'"  

Enter fullscreen mode Exit fullscreen mode

Even though setting.values[0] only had string values of "true" and "false" binding directly to it like these two statements:

 [checked]="setting.values[0]"
 [(ngModel)]="setting.values[0]

Enter fullscreen mode Exit fullscreen mode

Did not work! Not sure why, but I do know it can chew up time finding these syntactic errors.

JWP2020

Top comments (0)