ReferenceError: localStorage is not defined

前端 未结 3 2297
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 02:13

I am trying to make User Authentication with Angular and ASP.NET Core.

I am following the tutorial found here:

https://fullstackmark.com/post/10/user-authent

相关标签:
3条回答
  • 2021-01-05 02:42

    Put localStorage.getItem(...) on `ComponentDidMount()``

    0 讨论(0)
  • 2021-01-05 02:55

    You can use standard API for localstorage, like

    localStorage.setItem(k, v)
    

    and

    localStorage.getItem(k)
    

    but If you want a angular solution for this and find a good library for localstorage, one I'm using is this

    https://github.com/marcj/angular2-localstorage

    also

    https://www.npmjs.com/package/angular2-cool-storage

    is cool to use.

    0 讨论(0)
  • 2021-01-05 02:55

    The standard localStorage API should be available.

    No need to declare it.

    to set localStorage.setItem('name', 'storingSomething');

    to get localStorage.getItem('name');

    0 讨论(0)
提交回复
热议问题