6
votes

Ionic 2 has a Native Storage component for iOS and Android: https://ionicframework.com/docs/v2/native/nativestorage/

In the repo's readme (https://github.com/TheCocoaProject/cordova-plugin-nativestorage) is said that there is support for browser environment (it uses the LocalStorage fom the browser).

I tried to use it but when I run my Ionic in browser (ionic serve) the browser outputs something like this:

main.js:224 Native: tried calling NativeStorage.setItem, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator

In the browser environment the cordova is not injected. This makes senses, as long as the cordova.js only works for integration with the device's API.

Anyone knows if it is possible to use this plugin in the browser?

1
Have you considered using ionic run browser instead of ionic serve browser? When run is used the cordova.js and any plugins will be injected. So it is possible to use this plugin in the browser, but not with serve. Because with serve the app runs only as a webpage. - gillesC
I didn know this "ionic run browser"! I thought 'run' only works with ios, android, etc... Gonna try this! - Christian Benseler
@ChrisBenseler did the soln work for you? - Iceman

1 Answers

2
votes

Ionic / cordova made some changes in the CLI. The command to run with plugins is now ionic cordova run browser