Share and Learn To Write Code!

Programming articles, which help you to build your application. If something you are stuck to code and complete the program, just find here your question-related articles.

Share with   

Use of pure localStorage in angular 8 application to save data.

In Angular 8, how to use pure localStorage to save the app state or token details and etc.
Angular 8   Local Storage   Javascript   Web Storage  

Introduction


In this article, In angular 8 using pure localStorage method to save the token authentication states or different app states into localStorage.


LocalStorage


LocalStorage 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) Node js. Click here to install nodejs.

2) Angular Framework, If you do not know how to install angular in your system please check this article install Angular



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) localStorage supports 5MB limit across all major browsers.

2) localStorage 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.


Related Post :


Open model popup in Angular 6 | 7 | 8 | 9 using @ng-bootstrap NgbModal


How to install angular 8 in windows operating system.


Design student simple database using slick carousel implementation in angular 7 with firebase.


How to install bootstrap 4 in angular 9 | 8 | 7 | 6 | 5 | 4


Design custom bootstrap 4 pagination for angular project instead of using 3rd party pagination


How to install @ng-bootstrap to angular cli and uses of @ng-bootstrap


Install Node JS in windows machine and set environment path in settings.



1replies
Bhagwan V Zade
8 September 2020

Very helpful article for angular app.

Leave a reply
47
Registerd Users
89
Total Subscribers
59
Total Articles
52643
Total Views