Error storing item cordova_not_available

I Install Native Storage By run these commands

$ ionic cordova plugin add cordova-plugin-nativestorage
$ npm install --save @ionic-native/native-storage

And I have Import Native Storage in app.module.ts

•••••
import { NativeStorage } from '@ionic-native/native-storage';
•••••

/* SOME CODE*/

providers: [
  •••••
  NativeStorage
  •••••
]

And I use it in my HomePage (/pages/home/home)

•••••
import { NativeStorage } from '@ionic-native/native-storage';
•••••

constructor(private nativeStorage: NativeStorage) {}

/* SOME CODE */
ngOnInit(){
this.nativeStorage.setItem('myitem', {property: 'value', anotherProperty: 'anotherValue'})
  .then(
    () => console.log('Stored item!'),
    error => console.error('Error storing item', error)
  );
}

But after all these steps I got error in the console
Capture
my Question is What do I do to avoid this Error Error storing item cordova_not_available

Hello @amjado3!

Run on a emulate or device. Cordova don`t run on browser.

Thanks!

:+1:

Hi @medeiraf Thanks for your answer but cordova(NativeStorage) is available in the browser you can see Supported platforms of NativeStorage

1 Like

@amjado3

this.platform.ready().then(() => {
  this.nativeStorage.setItem('myitem', {property: 'value', anotherProperty: 'anotherValue'})
  .then(
    () => console.log('Stored item!'),
    error => console.error('Error storing item', error)
  ); });

Run on CLI: ionic cordova run browser

A this is a solution!

2 Likes