Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2: use NativeStorage in the browser

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?

like image 599
Christian Benseler Avatar asked Nov 03 '16 10:11

Christian Benseler


People also ask

Can I use localStorage in Ionic?

Ionic Storage abstracts all available mechansims for data storage such as native Cordova SQLite and browser storage APIs like IndexedDB, WebSQL or localStorage.

How do I see Ionic app in my browser?

Testing your app in a browser is as simple as running the serve command in your project's root folder. This will start a live-reload server for your project.

Does Ionic work on web?

Because Ionic is based on web technologies, it works just as well on desktop browsers as it does on mobile devices.


1 Answers

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

like image 143
Remco Vlierman Avatar answered Oct 05 '22 06:10

Remco Vlierman