I am using IonicStorage to save personalised data. I have a provider which is as follows:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Storage } from '@ionic/storage';
@Injectable()
export class UserProvider {
info: Info;
settings: Settings;
Defaults: {settings: Settings, info: Info};
constructor(public http: Http, private storage: Storage ) {
console.log('UserProvider Initialisation Started...');
this.Defaults = {
settings: {
Notifications: true,
AppTheme: 'primary'
},
info: null
};
this.info = this.Defaults.info;
this.settings = this.Defaults.settings;
// ---------------------------------------------
// Call Api for data and init into local storage
// ---------------------------------------------
this.initSettings();
}
initSettings() {
this.storage.get('userSettings').then((val) => {
// console.log(`UserInfo ${val}`);
if (val == null) {
console.log('Found val for userSettings.color null');
this.storage.set('userSettings', JSON.stringify(this.settings));
}
else {
this.settings = JSON.parse(val);
}
});
}
getInfo(): Info {
return this.info;
}
getSettings(): Settings {
// console.log(`this.settings-> ${JSON.stringify(this.settings)}`);
return this.settings;
}
update(info: Info, color?: string): void {
}
updateTheme(color: string): void {
this.settings.AppTheme = color;
this.storage.set('userSettings', JSON.stringify(this.settings));
}
}
export interface Info {
Name: string;
Sex: string;
DOB: any;
TOB: any;
POB: string,
Email: string;
City: string;
}
export interface Settings {
Notifications: boolean;
AppTheme: string;
}
I take settings from this provider when the app is loaded and things work very well when I do ionic serve.
Now I build the app and run it on my android device, the theme is not updating on the device (in simple words IonicStorage is not being used).
What can be possible reasons? Is IonicStorage only available on browser?
Please help, with regards and thanks.