Does anyone know, how the concept of shared preference in android, is used in ionic?. I tried a lot but couldn't understood how it is used in ionic.
In ionic we are use ionic storage: storage doc
You can install this plugin using following command
ionic cordova plugin add cordova-sqlite-storage
npm install --save @ionic/storage
Include it in your app.module.ts imports:
import { IonicStorageModule } from '@ionic/storage';
// Inside of your @NgModule
imports: [
IonicStorageModule.forRoot() // Add this
],
Then, on the page you're using it on, reference it like this:
constructor(private storage: Storage) { }
...
// set a key/value
storage.set('name', 'Max');
// Or to get a key/value pair its key value can get from any page after settting key value
storage.get('name').then((val) => {
console.log('Your age is', val);
});
}
Also you can also use localforage: enter link description here
Installation localforage:
npm install localforage
Uses: injecting
import * as localforage from "localforage";
Store value
localForage.setItem('key', 'value');
Getting value (same page or other page)
localforage.getItem('key');
Hope you will be helpful
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