Angular-Cli 管理通知的最佳方式 [英] Angular-Cli Best way to manage notices

查看:24
本文介绍了Angular-Cli 管理通知的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个旧站点迁移到我的新 Angular CLI 项目,并想通知我的用户.

I am migrating an old site to my new Angular CLI project and would like to offer my users a notice.

"This is a new site! To access your old account, go here..."

我需要的是一种让用户关闭通知并且永远不会返回的方法.我正在使用引导程序,所以结束部分很容易......但是为了坚持这一点,我传统上会使用 cookie.

What I need is a method for the user to close the notice and for it never to return. I am using bootstrap, so the closing part is easy enough... however to persist this I would traditionally use a cookie.

在 Angular 中这样做的最佳方法是什么,如果 cookie 是最好的方法,那么应该使用什么组件?

What is the best way to do this in Angular, if cookies are the best way, what component should be used?

谢谢!

推荐答案

虽然 cookie 被广泛用于此目的,但它并不是正确的选择.Cookie 用于需要随每个请求到达服务器的数据.

While cookies are widely used for this purpose, it would not be the right choice. Cookies are meant for data that needs to get to the server with every request.

您最好的选择是 localStorage 在此处查看 API:https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

your best option here is localStorage look at the API here: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

另请参阅此 quora 答案以了解 sessionStorage、localStorage 和 cookie 之间的区别.https://www.quora.com/sessionstorage-localstorage-and-Cookies 之间的区别是什么

Also look at this quora answer for the difference between sessionStorage, localStorage and cookie. https://www.quora.com/What-is-the-difference-between-sessionstorage-localstorage-and-Cookies

组件的选择取决于您,选择与您的应用相匹配的组件.

the choice of component is up to you, choose what matches your app.

这篇关于Angular-Cli 管理通知的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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