Search code examples
androidangularlocal-storageangular7mobile-devices

Is it possible to save data inside a database locally in Angular?


I work on an app, that won't have Internet-Connection during most of the time where it will be used.

The data for this app will be stored on a server and for updating the data it should be able to connect to that server and basically 'download' all of the new data or update the changed ones. Therefore I would need to be able to save that data on the device the app is running on, to be able to then retrieve it, when it is no longer connected.

The only thing that I found was localStorage, however, in my understanding, the data is not saved permanently but only temporary. I would need to be able to save it permanently on the device, until it connected and updated itself once again.

Is this in anyway possible?


Solution

  • You Can use localStorage and sessonStorage for this, Please refer below code:

    localStorage

    Set Value

    let items="Item1";
    localStorage.setItem(items,"Value")
    

    Get Value

    localStorage.getItem(items)
    

    sessionStorage

    Set Value

    let items="Item1";
    sessionStorage.setItem(items,"Value")
    

    Get Value

    sessionStorage.getItem(items)