【问题标题】:Any Angular directive for handling cookie law compliance?任何处理 cookie 法律合规性的 Angular 指令?
【发布时间】:2015-09-27 20:56:21
【问题描述】:

我最近决定开始尝试使网站符合欧盟 cookie 法律。我使用 AngularJS 作为我的前端框架。我一直在看这些 jquery 插件:

https://silktide.com/tools/cookie-consent/

http://cookiesdirective.com/

但是,如果可能的话,我更愿意使用角度优先的解决方案。有谁知道任何能够处理这个问题的角度指令?

【问题讨论】:

  • AngularJs 为你提供了cookie API?你还需要什么?我不明白

标签: jquery angularjs cookies angularjs-directive


【解决方案1】:

就这么简单。

angular.module('consent', ['ngCookies'])
.directive('consent', function ($cookies) {
  return {
    scope: {},
    template:
      '<div style="position: relative; z-index: 1000">' +
      '<div style="background: #ccc; position: fixed; bottom: 0; left: 0; right: 0" ng-hide="consent()">' +
      ' <a href="" ng-click="consent(true)">I\'m cookie consent</a>' +
      '</div>' +
      '</div>',
    controller: function ($scope) {
      var _consent = $cookies.get('consent');
      $scope.consent = function (consent) {
        if (consent === undefined) {
          return _consent;
        } else if (consent) {
          $cookies.put('consent', true);
          _consent = true;        
        }
      };
    }
  };
});

添加风格和动画来品味。

【讨论】:

    【解决方案2】:
    AngularJS provides the cookie API 
    

    查看链接 AngularJS Cookie API

    这就是你将如何使用它

    angular.module('cookiesExample', ['ngCookies'])
    .controller('ExampleController', ['$cookies', function($cookies) {
      // Retrieving a cookie
      var favoriteCookie = $cookies.get('myFavorite');
      // Setting a cookie
      $cookies.put('myFavorite', 'oatmeal');
    }]);
    

    【讨论】:

    • 问题是关于在网站上添加横幅以符合欧盟“Cookie 法”(cookielaw.org/the-cookie-law),也就是说,它与设置 cookie 或一般处理 cookie 无关。因此,您没有回答问题。
    猜你喜欢
    • 1970-01-01
    • 2021-07-07
    • 2013-03-12
    • 2011-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-29
    • 2017-03-07
    相关资源
    最近更新 更多