Ionic 3: How to store and use data globally in Ionic 3 Application

Ionic 3: How to store and use data globally in Ionic 3 Application







In Ionic 3, Many time you want to use same data on different pages. Every time transfer variable using navParam is an increase your code as well as using push() its effect on your app performance.

To perform this type of operation ionic 3 provides localStorage. Using this we can store data locally and use this data anywhere in our application.

Step 1: Create a Blank ionic project or use your existence

Step 2: Now in your First page create a localStorage variable using the following syntax

Page 1
let page1Data='This is Page 1 Data';
localStorage.setItem('storedData': page1Data);

Step 3:  Use this veriable in anyware globally 

Page 2
Use this Data on page 2 using
let page1Data= localStorage.getItem('storedData');
console.log(page1Data);If you want to clear data from local storage you can use localStorage.clear() or by setting empty value to localStorage veriable
Best Book for Entrepreneur ==> Strategies To Build Successful Web Agency

2 Responses to "Ionic 3: How to store and use data globally in Ionic 3 Application"

Iklan Atas Artikel

Advetisement

Advertisement

Iklan Bawah Artikel