ionic-framework: bug: Toggle call ionChange on view init

Type: <span ionic-type>bug</span>

Ionic Version: <span ionic-version>2.x</span>

Platform: <span ionic-platform>all</span>

<span ionic-description>This is my toggle: <ion-toggle [(ngModel)]=“workMode” (ionChange)=“workModeChanged()”></ion-toggle>

if this.workMode == true so workModeChanged callback will called on page init, even without click on the toggle. that is the bug. if this.workMode == false there is no bug.

Thanks</span>

<span is-issue-template></span>

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I can reproduce the issue again on Ionic 3. I have fetched the value from backend and set the field in both constructor and ngOnInit. Both ways cause event to fire.

Ionic version:

“ionic-angular”: “3.0.1”

Constructor code:

constructor(

private navCtrl: NavController,
private popoverCtrl: PopoverController,
private userService: UserService,
private toastHelper: ToastHelper) {
  this.userService.getUser().subscribe(
  user => {
    this.disableAccount = user.disableAccount;
  },
  err => {
    this.toastHelper.showTranslatedToast('connection.serverUnavailable');
    console.log(err);
  }
);

}

HTML:

<ion-item> <ion-label>Disable account</ion-label> <ion-toggle [(ngModel)]="disableAccount" (ionChange)="toggleDisableAccount()" checked="false"></ion-toggle> </ion-item>