Angular 2中的本地存储 [英] Local storage in Angular 2

查看:149
本文介绍了Angular 2中的本地存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在浏览器的会话中存储数据并检索数据,直到会话退出。如何在Angular 2中使用本地和会话存储?

I need to store data in the browser's session and retrieve the data until the session exits. How do you use local and session storage in Angular 2?

推荐答案

标准 localStorage API ,例如:

The standard localStorage API should be available, just do e.g.:

localStorage.setItem('whatever', 'something');

这是得到广泛支持

请注意,您需要将dom添加到lib tsconfig.json 中的数组(如果您还没有)。

Note that you will need to add "dom" to the "lib" array in your tsconfig.json if you don't already have it.

这篇关于Angular 2中的本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆