【问题标题】:How to add Angular Enable Cookies Popup Message Box如何添加 Angular Enable Cookies 弹出消息框
【发布时间】:2020-05-26 09:14:50
【问题描述】:

我正在使用 Angular 9 开发一个应用程序,我需要在我的主页底部添加一条弹出消息,要求启用 cookie(正如我在大多数网站中看到的那样)。有没有办法做到这一点。请帮助(我是角度的初学者)

【问题讨论】:

标签: angular typescript cookies popup angular9


【解决方案1】:

在 index.html 中添加以下链接:

<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" />
  <script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script>

在 ngOnInit 上的 app.component.ts 中添加以下逻辑:

let cc = window as any;
       cc.cookieconsent.initialise({
         palette: {
           popup: {
             background: "#164969"
           },
           button: {
             background: "#ffe000",
             text: "#164969"
           }
         },
         theme: "classic",
         content: {
           message: this.cookieMessage,
           dismiss: this.cookieDismiss,
           link: this.cookieLinkText,
           href: environment.Frontend + "/dataprivacy" 
         }
       });

参考:https://developersde.azurewebsites.net/2018/10/29/implementing-cookie-for-angular-app/

【讨论】:

    猜你喜欢
    • 2011-09-08
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-29
    • 2023-03-21
    相关资源
    最近更新 更多