Dynamically Checkbox checked

According to the forum suggestion, Code was successfully use for Checked a Checkbox, but when need to get the that checked checkbox value, value getting “null” instead of “true”.
If i toggle that checked checkbox by clicking mouse, then its come with “true” value, but if checkbox checked by code process then it come with “null” value.

HTML Code
<ion-checkbox color=“secondary” slot=“start” [checked]=“isChecked” formControlName=“chkBxRememberMe”>

login.page.ts file code
ngOnInit() { this.isChecked = true; }
userLogin(){ console.log(“Reme”, this.LoginForm.value.chkBxRememberMe); }

Please help me out.

According to the docs, you need to add a value attribute to your HTML if you’re using it in a form.

The value of a toggle is analogous to the value of a <input type="checkbox"> , it’s only used when the toggle participates in a native <form> .

    <ion-checkbox
      [checked]="isChecked"
      value="chkBxRememberMe"
      (ionChange)="lookatme($event)"
    ></ion-checkbox>
  lookatme(e: any) {
    console.log(e.target.checked);
  }

Can you explain what you mean by “if checkbox checked by code process?”

You have too many cooks in the kitchen. Since you are already binding a form control, don’t bind ngModel and don’t bind checked. Simply assign to the value of your form control.

1 Like