I try to use this in my Ionic 2 application : https://ionicframework.com/docs/v2/storage/
I already run
cordova plugin add cordova-sqlite-storage --
Since Ionic 2.2.0, it's recommended to use @ionic/storage version 2.0.0. Configuration in app.modules.ts has changed since the previous version. The error occurs if you haven't changed everything in the right way.
In app.modules.ts do following changes:
Change import statement:
from: import { Storage } from '@ionic/storage';
to: import { IonicStorageModule } from '@ionic/storage';
Add the following to the imports array:
IonicStorageModule.forRoot()
The import array should look like below:
imports: [
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot()
],
NOTE: Do not make any change in imports of Storage in any other files.
Your app.module.ts should look like,
import { Storage } from '@ionic/storage';
export function provideStorage() {
return new Storage(['sqlite', 'websql', 'indexeddb'], { name: 'database_name' });
}
@NgModule({
declarations: [
],
imports: [
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
],
providers: [
{ provide: Storage, useFactory: provideStorage }, Storage
]
})
You have to use set() and get() methods to store and retrieve data in your pages. Have a look at Ionic 2 Storage Tutorial Blog with example video. Hope this helps