Any Angular directive for checking cookie compliance?

I recently decided to start work on a site that complies with EU cookie laws. I am using AngularJS as the framework for the frontend. I looked at these jquery plugins:

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

http://cookiesdirective.com/

However, I would prefer to use the first angular solution, if at all possible. Does anyone know of any angular directive that can handle this?

+4
source share
2 answers

Easy as that.

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;        
        }
      };
    }
  };
});

Add style and animation to taste.

+14
source
AngularJS provides the cookie API 

Check out the AngularJS Cookie API Link

This is how you will use it

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

All Articles