question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ionic 4 Toggle ngModel does not work and checked handle does not exist

See original GitHub issue

Bug Report

Ionic version:

[x] 4.x

Current behavior: My project uses ion-toggle and i set value checked of this tag by variable and some trigger. But when ionChange event run, i change value of variable by two-way binding, it not change in UI, i try with checked handle but the handle was off in #17012 In ionic framework docs, there are not any guide of this issue, can body have some solutions for my problem?

Related code:

in UI html

<ion-toggle [(ngModel)]="var1" mode="ios" 
        color="success" (ionChange)="change($event)">
</ion-toggle>

In ts first code

change(e){
       if(this.var1 == false && this.var2 == false){
              e.checked = true;
       }
}

In ts second code

change(e){
       if(this.var1 == false && this.var2 == false){
              this.var1 = true;
       }
}

Other information:

Ionic info:

Ionic:

   ionic (Ionic CLI)             : 4.10.3 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.1.1
   @angular-devkit/build-angular : 0.13.6
   @angular-devkit/schematics    : 7.2.4
   @angular/cli                  : 7.3.6
   @ionic/angular-toolkit        : 1.4.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : none
   Cordova Plugins       : no whitelisted plugins (10 plugins total)

System:

   Android SDK Tools : 26.1.1 (/home/conganhpham/sdk-tools-linux-4333796)
   NodeJS            : v8.10.0 (/usr/bin/node)
   npm               : 6.8.0
   OS                : Linux 4.15

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
saladggcommented, May 31, 2019

@phamconganh , As of ionic 4, you access checked by adding .detail to the change method params; <ion-toggle [(ngModel)]=“var1” mode=“ios” color=“success” (ionChange)=“change($event.detail)”> </ion-toggle>

3reactions
liamdebeasicommented, Mar 22, 2019

Hi there,

Thanks for the follow up. I was able to reproduce the issue. We will look into it!

As a temporary workaround, you can do:

setTimeout(() => {
  this.var1 = true;
  this.var2 = true;
  this.var3 = true;
  this.var4 = true;
 }, 0);

This approach should be removed when this bug gets fixed, but it should do the job for now.

Thanks for using Ionic!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ion-toggle checked doesn't wok with ngModel ionic3
Using [(ngModel)] with an ion-toggle component doesn't visually checked the component at the start if the bound value is true.
Read more >
Ion-toggle doesn't work - Ionic Angular
Hi everyone, I have a problem with a toggle, I would like to have 2 states for 2 different functions, but I always...
Read more >
Slide toggle | Angular Material
Used to set the aria-labelledby attribute on the underlying input element. @Input(). checked: boolean. Whether the slide-toggle element is checked or not.
Read more >
ion-toggle for State change problem : r/ionic - Reddit
I am trying to use ion-toggle. I am initializing his state based on an isStatusInProgress variable. Until here, everything is fine. When I...
Read more >
48 answers on StackOverflow to the most popular Angular ...
map is not a function in [null]; How to use jQuery with Angular? ... directive's data-bound properties have been checked for the first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found