Hi
Let me explain to you. What I’ve done and what is remaining.
Done:
Checkbox value is saved in storage and it is successfully working.
Remaining:
On clicking checkbox, I’m adding a class to content but I don’t know how to save the class to storage.
Popover.html
<ion-item>
<ion-label>English</ion-label>
<ion-checkbox (click)="activateEnglish()" [checked]="EnglishCheckbox"></ion-checkbox>
</ion-item>
Popover.ts
constructor(public navCtrl: NavController, public navParams: NavParams, public viewCtrl: ViewController, private storage: Storage) {
storage.get('EnglishLang').then(EnglishLang=> this.EnglishCheckbox = EnglishLang);
}
EnglishCheckbox: boolean = false;
//Active English Function
activateEnglish(){
this.textEle.classList.toggle('showEnglish');
this.storage.set('name', 'test').then(() => {
if (this.EnglishCheckbox){
this.EnglishCheckbox = false;
this.storage.set('EnglishLang', 'false');
} else {
this.EnglishCheckbox = true;
this.storage.set('EnglishLang', 'true');
}
});
}
On click checkbox I’m adding showEnglish class to my content but it is not saving it to storage. How to do it.
Best Regards
yajuve
3
use (ionChange) instead of (click)
...
(ionChange)="activateEnglish()"
...
How to save it into storage?
yajuve
5
In your TS file
activatEnglisg() {
this.storage.set('yourKey', 'yourValue').then(() => {
console.log('success');
});
}
activateEnglish(){
//Add Class to content
this.textEle.classList.toggle('showEnglish');
//Save Checkbox Value
this.storage.set('name', 'test').then(() => {
if (this.EnglishCheckbox){
this.EnglishCheckbox = false;
this.storage.set('EnglishLang', 'false');
} else {
this.EnglishCheckbox = true;
this.storage.set('EnglishLang', 'true');
}
});
}
this.textEle.classList.toggle(‘showEnglish’);
I want to save it into the storage then how I’ll do it?
yajuve
7
what does this ? it’s a function ?
It is adding a “showEnglish” class to my content in another page.
yajuve
9
So you want save this css class ‘showEnglish’ in your storage ?
that’s right ?
yajuve
11
save it in storage
this.storage.set('showEnglishKey', 'showEnglish').then(() => {
});
to get it after saving
this.storage.get('showEnglishKey').then((resp) => {
this.variable = resp; // will contains showEnglish
});
Thanks man! Let me try this.
What variable will be here?
I haven’t declared any.
yajuve
14
chose any one to store your value from storage
for example declare a variable in your class in TS file.
It is saving the value to storage but class not adding to content.
I’m doing it like this.
saveClass: any;
activateEnglish(){
this.storage.set('showEnglishKey', 'showEnglish').then(() => {
this.textEle.classList.toggle('showEnglish');
});
and getting it like this:
this.storage.get('showEnglishKey').then((resp) => {
this.saveClass = resp; // will contains showEnglish
});
yajuve
16
try this
this.storage.get('showEnglishKey').then((resp) => {
this.saveClass = resp; // will contains showEnglish
this.textEle.classList.toggle( this.saveClass );
});
1 Like
Thanks man! It is working now. Thanks a lot…
