任何 Angular 处理 cookie 法律合规性的指令?
Any Angular directive for handling cookie law compliance?
我最近决定开始尝试使网站符合欧盟 cookie 法律。我使用 AngularJS 作为我的前端框架。我一直在看这些 jquery 插件:
https://silktide.com/tools/cookie-consent/
但是,如果可能的话,我更愿意使用 angular 第一种解决方案。有谁知道任何能够处理这个的 angular 指令?
AngularJS provides the cookie API
查看 link
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');
}]);
就这么简单。
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;
}
};
}
};
});
添加样式和动画。
我最近决定开始尝试使网站符合欧盟 cookie 法律。我使用 AngularJS 作为我的前端框架。我一直在看这些 jquery 插件:
https://silktide.com/tools/cookie-consent/
但是,如果可能的话,我更愿意使用 angular 第一种解决方案。有谁知道任何能够处理这个的 angular 指令?
AngularJS provides the cookie API
查看 link 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');
}]);
就这么简单。
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;
}
};
}
};
});
添加样式和动画。