Search code examples
angulartypescriptionic2

Ionic2 checkbox with formControlName


Actually I am stuck with an issue when using checkbox in ionic2.

I am using checkbox as:

<ion-item>
    <ion-label>Agree</ion-label>
    <ion-checkbox color="dark" id="agree" name='agree' class="form-control" formControlName="agree" [checked]="false" ></ion-checkbox>
  </ion-item>

In .ts i am fetching its value as :

console.log(this.timelogForm.controls['agree'].value);

I want it to be unchecked initially.

My issues are :

  1. on using formControlName="agree" it is checked ..

  2. I get its value in .ts if it is once clicked but I want if it's not clicked on submit I get false and if checked I get true..

Any help please


Solution

  • I resolved it on my own hope it helps someone..

    I set its value as false like:

    this.logForm = formBuilder.group({
            'agree': ['false'],
        });
    

    Hope it helps someone.