Angular Local Storage 💾

Angular + Local Storage

Recently I was implementing local storage in Angular. I came across the marcj angular2-localstorage. He is using decorator which makes it super easy to save and restore automatically a variable state in local or session storage.

Usage

In your component just decorate your variable with @LocalStorage or @SessionStorage and you are done.

Local Storage

It’s great idea but he’s implementation is quite swollen. So I have decided to implement it on my own. Here is minimal example to understand how it works. So you can implement it on your own.

Session Storage

For session storage it’s alike.

Buy me a coffeeBuy me a coffee