Problem with ionic storage in ionic3

I switched to ionic3, but it gives me error wherever I used ionic storage from @ionic/storage in my code. It says that supplied parameters do not match any signature of call target wherever I had used “Storage.get()” and “Storage.set()” functions… Earlier they were working fine with ionic2. I guess they changed the arguments of these functions… Please help me out in this.

iOnic 3 is not a new framework they just updated to Angular 4. So they didn’t changed the iOnic storage functionality.

Can you share your code? And have you followed the upgrade guide?

Yes I followed the upgrade guide… The code I am using is:

import { Storage } from ‘@ionic/storage’;

new Storage().set(‘anyKey’, ‘anyValue’);

new Storage().get(‘anyKey’).then(value => {
//code
});

Error I am getting is:

Typescript Error
Supplied parameters do not match any signature of call target.

You should inject the storage in your constructor. And you should also user the method this.storage.ready().then(); to be sure your storage is ready.
And use a separate provider class for your storage methods.

import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
@Injectable()
export class DataServiceProvider {
  constructor(private storage: Storage) { }
  setShowPresentation(value: boolean) {
return this.storage.set('showPresentation', value);
  }
  getShowPresentation() {
return this.storage.get('showPresentation');
  }
}

By returning the method you can always call the .then() method to check if it worked correctly.

2 Likes

Yes injecting storage in constructor solved my problem… I used this.storage.set() & this.storage.get()…Thank you for it… But earlier it worked fine with ionic2… Now I need to change this line everywhere in my whole project…

And yes, I’ll make a provider class as you said… Just tell me one more thing, is switching to ionic 3 when it is in its beta version a good idea? I’ll have a production app on ionic 3…

They released iOnic 3.1 stable last week so it is out of beta :slight_smile:
I had no problems with m project’s after the update

1 Like

This breaking change was necessary in order to facilitate including only the native plugin shims that you are actually using. A well worthwhile tradeoff in my opinion.

1 Like

Thank you :slight_smile:

1 Like

When switching to Ionic 3 you also upgraded to Ionic Native 3 (see your package.json). This is what causes these changes. You could theoretically go back to the former Ionic Native version and keep your old code - but because of the reasons @rapropos mentioned I wouldn’t suggest so.

1 Like