Share with   

Use of pure local storage in angular 8 application to save data

In Angular 8, how to use pure local storage to save the app state or token details and etc.


Introduction

In this article, In Angular 8 using pure local storage method to save the token authentication states or different app states into local storage.

 

Local Storage

Local storage is one of the Web storage property to save the states or data with no expiration date and time. You can store and access data from web storage in the browser will persist even after the browser window has been closed.

 

Prerequisite

1) Install Node js

2) Install Angular & Create Angular App

 

To use localStorage in your angular applications, There are some methods to set, get, remove and clear

setItem()

Add key and value to localStorage.

const person = {
   name: 'Obaseki Nosa',
   location: 'Lagos',
};
localStorage.setItem('user', JSON.stringify(person));

 

getItem()

Retrieve value by the key from localStorage.

const user = JSON.parse(localStorage.getItem('user'));

 

removeItem()

Remove an item by key from.

localStorage.removeItem('user');

 

clear()

Clear all localstorage data.

localStorage.clear();

 

Limitations and of localStorage

1) local storage supports 5MB limit across all major browsers.

2) local storage is less secure data without protection anyone can access this data.

 

Thank you for watching article.

If you like please like and share to your developer friends.

Author Image
Guest User

0 Comments