Angular - Storage mechanism


There are different storage mechanism available in angular.We need to choose which one to use based on different scenarios.

Local Storage


If we use localstorage, then we can retrieve the data across different tabs and the data will last even if we close the browser. Till the time we clear the cache of the browser.


In order to  set local storage         localStorage.setItem("key", "value")
In order to  get local storage         localStorage.getItem("key")

Session Storage


If we use session storage, then the data will last till the time we close the browser.The data can't be used across different tabs in the browser.


In order to set session storage       sessionStorage.setItem("key", "value")
In order to  get session storage      sessionStorage.getItem("key")

Comments

  1. Thank you sir,for more information join my udemy course on Angular
    https://www.udemy.com/angular-for-beginners-b

    ReplyDelete

Post a Comment