Home > Mobile >  Using local storage on Angular
Using local storage on Angular

Time:12-22

I'm trying to make a simple phonebook using Angular, but I'm struggling with making my "app" store the information inserted to local storage.

Here is what I have so far, so if anyone has time to take a peak, I would appreciate it very much.

https://easyupload.io/m/uk7r3f

CodePudding user response:

The following snippet accesses the current domain's local Storage object and adds a data item to it using Storage.setItem().

localStorage.setItem('myCat', 'Tom');

The syntax for reading the localStorage item is as follows:

const cat = localStorage.getItem('myCat');

The syntax for removing the localStorage item is as follows:

localStorage.removeItem('myCat');

The syntax for removing all the localStorage items is as follows:

localStorage.clear();

Note: Please refer to the Using the Web Storage API article for a full example.

Source: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage#example

CodePudding user response:

you can use setItem, getItem, removeItem methods to perform CRUD operation using localStorage

   localStorage.setItem('key', 'value');

For more information you can follow: Add DATA in localStorage

CodePudding user response:

localStorage.setItem('key', 'value') = > allows you to store an item in the browser storage

localStorage.getItem('key') = > allows you to read the value for the specified key item from the browser storage. for more information : https://www.journaldunet.fr/web-tech/developpement/1441263-comment-gerer-le-stockage-en-local-dans-la-session-d-un-navigateur-avec-angular/

  • Related