here is my .html file
<ion-item no-lines (click)="update()" >
<ion-label> Notification</ion-label>
<ion-toggle [(ngModel)]="notify" ></ion-toggle>
</ion-item>
the above code works when i click on the Notification
text but when i click on the ion-toggle
i am not able to invoke the function what should i do to invoke the function.
here is my .ts file
update(){
console.log("invoking notification");
}
Toggles are switches that change the state of a single option. They can be switched on or off by pressing or swiping them. Toggles can also be checked programmatically by setting the checked property.
Slap ion-toggle-text on any existing ion-toggle and you're good to go. On/off text can be set with either the ng-true-value / ng-false-value attributes or with a ; separated value with the ion-toggle-text attribute. If no text is provided it defaults to "on" & "off".
To fix Can't bind to 'ngModel' since it isn't a known property of 'input' error in Angular applications we have to import FormModule in app. module. ts file. If you are using FormBuilder class to create reactive form we have to import ReactiveFormsModule as well to avoid below error.
The different Toggle Switch Button sizes available are default and small. To reduce the size of default Toggle Switch Button to small, set the CssClass property to e-small .
If you use ngModel
it's best to use ngModelChange
<ion-toggle [(ngModel)]="notify" (ngModelChange)="update($event)" ></ion-toggle>
otherwise you can use
<ion-toggle (ionChange)="update($event)"></ion-toggle>
See also https://ionicframework.com/docs/api/components/toggle/Toggle/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With