ionic 4 Storage Injection error: no provider
I had the same problem... it resolved after adding the following lines in app.module.ts
import { IonicStorageModule } from '@ionic/storage'
;
add the same in imports section:
imports: [ BrowserModule, HttpClientModule, IonicModule.forRoot(), IonicStorageModule.forRoot(), AppRoutingModule ]
For anyone else coming here from Google that's using PhpStorm, my issue was that, possibly because of the app.module import, the page I used storage on didn't auto-add the import statement. So my code went from looking like:
export class MyApp { constructor(private storage: Storage) { } ... // set a key/value storage.set('name', 'Max'); // Or to get a key/value pair storage.get('age').then((val) => { console.log('Your age is', val); });}
To this:
import { Storage } from '@ionic/storage'; // This line added manually.export class MyApp { constructor(private storage: Storage) { } ... // set a key/value storage.set('name', 'Max'); // Or to get a key/value pair storage.get('age').then((val) => { console.log('Your age is', val); });}
I have the same problem on No provider for Storage
.
Yet my problem was my IDE auto-import only generated import { IonicStorageModule } from "@ionic/storage";
. Problem fixed after adding Storage,
. Which is not in your case, but hope to help other readers later.