March 15, 2018

Error: Can't resolve all parameters for Storage


Ionic 3 and Angular2 Project. I never noticed this error when using it with Ionic, but it happened now using the @ionic/storage
Error: Can't resolve all parameters for Storage
It it a runtime error and I set up my app.module.ts as follows:
...
import { Storage } from '@ionic/storage';
@NgModule({
  ...
  providers: [
    Storage,
    ...
  ],
  ...
})
export class AppModule{ }

I’ve found a solution using a custom provider like this:
...
import { Storage } from '@ionic/storage';

export function provideStorage() {
 return new Storage();
}

@NgModule({
  providers: [
    ...
        { provide: Storage, useFactory: provideStorage },
    ...
  ],
  ...
})
export class AppModule{ }

And everything works.
Also remember to check out the package version of the @ionic/storage in the package.json file. It should be the latest.
Mine is 2.1.3
"@ionic/storage": "2.1.3",


No comments:

Post a Comment