npm install --save @ionic-native/native-storage
import { NativeStorage } from '@ionic-native/native-storage';
constructor(private nativeStorage: NativeStorage) { }
...
this.nativeStorage.setItem('myitem', {property: 'value', anotherProperty: 'anotherValue'})
.then(
() => console.log('Stored item!'),
error => console.error('Error storing item', error)
);
this.nativeStorage.getItem('myitem')
.then(
data => console.log(data),
error => console.error(error)
);
For ionic v2 we can use native storage
Add plugins using cmd
$ ionic cordova plugin add cordova-plugin-nativestorage
$ npm install --save @ionic-native/native-storage
In appmodule.ts
import { NativeStorage } from '@ionic-native/native-storage';
@NgModule({
declarations: [
// pages to be added
],
imports: [
BrowserModule,
NgCalendarModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
//pages to be added
],
providers: [
SplashScreen,
NativeStorage,
{ provide: ErrorHandler, useClass: IonicErrorHandler }
]
})
export class AppModule { }
To set and get values import { NativeStorage } from '@ionic-native/native-storage';
var array=[];
this.nativeStorage.setItem("setting value", array);
this.nativeStorage.getItem("setting value"),then(
data => {
console.log("stored value", data)
})
Hope this helps