How to share the data across the pages which resides in application.Can anyone tell about localstorage in nativescript?
If you are using NS8, use "application-settings" from @nativescript/core
For example:
import * as appSettings from "@nativescript/core/application-settings";
...
appSettings.setString("token", response.token);
appSettings.setString("userId", response.user.id.toString());
appSettings.setString("email", email);
If you install the "nativescript-localstorage" plugin,
tns plugin install nativescript-localstorage
You will then have access to both SessionStorage and LocalStorage just as if you were using a browser.
From the docs:
To set a value:
require( "nativescript-localstorage" );
localStorage.setItem('Another Plugin', 'By Master Technology');
localStorage.getItem('Another Plugin'); // Returns: "By Master Technology"
or
const LS = require( "nativescript-localstorage" );
LS.setItem('Another Plugin', 'By Master Technology');
LS.getItem('Another Plugin'); // Returns: "By Master Technology"
Disclaimer I'm the author of said plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With