Ionic2 Error: “No provider for Storage”

前端 未结 4 707
孤独总比滥情好
孤独总比滥情好 2020-12-29 23:14

After reading everything I could find, and failing, I must ask here:

I am trying to use ionic2\'s Storage, just like the doc tells me to,

doc: https://ionicf

相关标签:
4条回答
  • 2020-12-29 23:18

    I had the same issue. I added this to app.module.ts:

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

    And, this to imports parts of the app.module.ts:

    IonicStorageModule.forRoot(),
    
    0 讨论(0)
  • 2020-12-29 23:23

    In my case, I forgot to add the following in app.module.ts

    import { IonicStorageModule } from '@ionic/storage';
    
    @NgModul({ 
      ..., 
      Imports: [
      ...
        IonicStorageModule.forRoot()
    ],
    
    0 讨论(0)
  • 2020-12-29 23:38

    first do this npm install --save @ionic/storage

    I managed to get this working using this ..

    Inside app.module.ts

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

    And then ...

    providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}, Storage]
    

    And then in my page.ts

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

    In the constructor ...

    public storage: Storage
    

    And then within the guts of my code ..

    this.storage.get('date').then((value) => {
      // blah
    });
    
    0 讨论(0)
  • 2020-12-29 23:45

    Firstly you need to install: npm install --save @ionic/storage

    The problem was in app.ts:

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

    Capital 'S' instead of non capital 's':

    from '@ionic/Storage'
    

    instead of:

    from '@ionic/storage'
    

    No idea why the compiler wouldn't catch that if it's a problem, but it didn't.

    Thanks to @chairmanmow

    0 讨论(0)
提交回复
热议问题