Ionic 4 Toggle ngModel does not work and checked handle does not exist
See original GitHub issueBug 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:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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>
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:
This approach should be removed when this bug gets fixed, but it should do the job for now.
Thanks for using Ionic!