mercredi 5 mai 2021

how to make a checkbox 'true' by default on pageload in angular

I have a checkbox that I require to be 'checked' on page load, and then the user can turn it 'off' if they wish. but when the page loads, the check box must be populated.

I thought it was as simple as adding [checked]="true" as some Stack questions have suggested. but this is not working for me.

<label class="custom-control custom-checkbox" style="display: block">
              <input type="checkbox" class="custom-control-input" id="myCheckbox" name="checkboxplicy"
                     [(ngModel)]="hasaccepted" [checked]="true" (ngModelChange)="parentcheckbox($event,check1,check2,check3)">
 </label>

any ideas?




Aucun commentaire:

Enregistrer un commentaire