Types of HTML Local storage


HTML local storage provides two objects for storing data on the client which you can access through AngularJS service as well

  1. Local storage: window.localStorage stores data with no expiration date

To use this localStorage in angularJS, You need to use the service provided by angular i.e. $window to access Window object.

Few methods of $window is as below:

$window.localStorage.setItem(key,value) to store,
$window.localStorage.getItem(key) to retrieve and
$window.localStorage.removeItem(key) then you can access the values in any page.

2. Session storage: window.sessionStorage – stores data for one session i.e. data is lost when browser tab gets closed.

few methods of sessionStorage is as below:

getItem(key) to retrieves the value for the given key or null if the key doesn’t exist.
setItem(key, value) to sets the value for the given key.
removeItem(key) to removes the key completely.
key(position) to returns the key for the value in the given numeric position.
clear() to removes all key-value pairs.

Join Discussion

This site uses Akismet to reduce spam. Learn how your comment data is processed.