我应该直接在Angular 2中使用本地存储吗 [英] Should i use Local storage directly in Angular 2
本文介绍了我应该直接在Angular 2中使用本地存储吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我应该直接在组件中使用本地存储吗?有人说直接使用窗口函数是一种不好的做法.
在角度2中使用本地存储是一种好的做法
提前谢谢
解决方案
最佳实践是实现处理此问题的 Service
.
该 Service
可以检查是否存在 localstorage
并使用它..如果没有,它将忽略那些set/get函数或以任何其他方式模拟它们./p>
Should i use local Storage directly in component , someone said it is bad practice to use window functions directly .
What would be good practice to use local storage in angular 2
Thank you in advance
解决方案
Best practice would be to implement a Service
that handles this.
Thid Service
could check if the localstorage
is present and use it.. if not it ignores those set/get functions or mock them in any other way..
这篇关于我应该直接在Angular 2中使用本地存储吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文