Native Storage Error - plugin not installed

I use the Native Storage example and run it in iOS simulator. I have installed the native storage with command

ionic plugin add cordova-plugin-nativestorage

But it gives Error storing item: plugin_not_installed

The code is as in the example of Ionic2 document

import { NativeStorage } from ‘ionic-native’;

ionViewWillEnter() {
NativeStorage.setItem(‘myitem’, {property: ‘value’, anotherProperty: ‘anotherValue’})
.then(
() => this.result = ‘Stored item!’,
error => this.result = ‘Error storing item:’ + error
);
}

What could be the reason? Thanks!

2 Likes

I found solution. It worked after I moved the NativeStorage part to a button click event. It seems that ionViewWillEnter hasn’t loaded plugin yet.

You can use Platform.ready() to wait until Cordova plugins have been initialised.

2 Likes

Thanks a lot ! I will make that check.

Thank you for this mirkonasato.