Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48981

Ion Toggle is not saved - Storage (ionic)

$
0
0

Hi, I have a simple problem. I have a list of Toggles in my app. I need that when users check or uncheck Toggle, the changes are saved after the app is closed. I’m using StorageModule.

I used this code to add Storage:

ionic cordova plugin add cordova-sqlite-storage

Then I made the additions to my app.module.ts

my HTML:

<ion-toggle slot="end" color="secondary" [(ngModel)]="Ativar" (ionChange)="Toggle1()"></ion-toggle>

my TS:

import { Storage } from '@ionic/storage-angular';

export class Tab1Page {
 
 public Ativar : boolean;



 constructor(public alert: AlertController, public navCtrl: NavController, 
private storage: Storage) { }

 async Toggle1() {
     if(this.Ativar == true){
       this.storage.set('ativar', true);
     }
     if(this.Ativar == false){
       this.storage.set('ativar', false);
     }
     this.storage.get('ativar').then((data) => {
       this.Ativar = data;
   });
   };

I use the app emulator to run the app on my phone:

ionic cordova run android

When I make changes in Toggle and close the app, when I open it, the changes are not saved. I’ve been stuck at this stage for a long time. I just wish the toggle was saved. Can someone help me? I’m lost

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>