Error: No provider for Storage

So I wanted to use a provider for saving my data in the application. It looks like this:

import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage'


@Injectable()
export class Data {

  constructor(public http: Http, public storage: Storage) {
    console.log('Hello DataProvider Provider');
  }


  getData() {
    return this.storage.get('todolistEntries');
  }

  save(todolistEntries) {
    let newTodolistEntries = JSON.stringify(todolistEntries);
    this.storage.set('todolistEntries', newTodolistEntries);
  }

}

I’ve imported it into app.module.ts:

import { IonicStorageModule } from '@ionic/storage';

...

providers: [
        StatusBar,
        SplashScreen,
        { provide: ErrorHandler, useClass: IonicErrorHandler },
    Data
    ]   

and injected it into my file:

import { Data } from '../../providers/data/data'

But as soon as i am setting that provider up like this:

 constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController, public dataService: Data) {}

i am getting a error message:

Uncaught (in promise): Error: No provider for Storage! Error: No provider for Storage! at injectionError (http://localhost:8100/build/vendor.js:1590:86) at noProviderError

Any ideas whats wrong?

Do you have IonicStorageModule.forRoot() in the imports array in app.module.ts?

11 Likes

Gosh. Sorry for wasting your time!
Thank you so much!

2 Likes

i have error as same like this? can you tell me the solution please.

In the app.module.ts replaces IonicStorageModule by IonicStorageModule.forRoot()

i did that but same error any solution?

for me too, its defined in app.module for root, and still get this error