Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access HTML5 local storage from Angular2

I'm following this tutorial: https://medium.com/@blacksonic86/authentication-in-angular-2-958052c64492 about authentication in Angular2.

I've the issue with this part:

import localStorage from 'localStorage';

I've read somewhere else that I should use this library https://github.com/marcj/angular2-localstorage to access local storage in HTML5. Is it really the only option? Can I access HTML5 local storage from angular2 without using extra modules?

like image 585
Daniel Stradowski Avatar asked Sep 01 '16 09:09

Daniel Stradowski


1 Answers

I noticed that the local storage project is seeking someone to takeover and is not currently being maintained. So I am not going to use it until then. I was able to find the a fix in my tsconfig.json file.

In the property lib you can simply add dom

"lib": [
      "es2016",
      "dom"
    ]

This is supported in the compiler options https://www.typescriptlang.org/docs/handbook/compiler-options.html.

I had to restart visual studio code for this to remove the errors.

like image 73
Winnemucca Avatar answered Oct 09 '22 08:10

Winnemucca