Angular Consent
Easily show consent messages that keep appearing until the user clicks them away.
Useful if you need to show legal disclaimers (e.g. to conform to the EU Cookie Consent law).
- very lightweight (~1KB)
- use your own markup and CSS to make the messages fit perfectly in your application
- supports multiple consent messages on the same page
Requirements:
Quick example
<!-- add consent attribute to any element --><!-- to expose $consent controller to children --> <!-- then use your own custom markup to create the message --> This web application uses cookies to store private data. Agree
Usage
First install the module using bower:
$ bower install angular-cookies$ bower install angular-consent
and add the library to your application:
Then add the ngCookies
and angularConsent
modules to the dependencies of your AngularJS application module:
angular;
Now you can use the consent
directive anywhere in your markup:
<!-- add consent attribute to any element --><!-- to expose $consent controller to children --> <!-- then use your own custom markup to create the message --> This web application uses cookies to store private data. Agree
To create multiple consents in a single application, pass a unique key to the consent
attribute:
<!-- consent for cookie disclaimer --> This website uses cookies. Ok, I understand <!-- consent for privacy disclaimer --> This website stores private data. Ok, I understand
You can also re-use a consent across your page or application:
<!-- display consent message in header --> This website uses cookies. <!-- and show the button in the footer --> Ok, I understand
By default cookies are stored for 360 days, but you can customize cookie options on a consent level:
<!-- expirationDate should be string string of form 'Wdy, DD Mon YYYY HH:MM:SS GMT' --> This website uses cookies. The cookie will be stored until expiration date.
The $consent API
The following methods are available on the $consent
object:
$consent.hasAlreadyAgreed()
Whether or not the user has already agreed.
Arguments
None.
Returns
Boolean.
$consent.hasNotAgreedYet()
Whether or not the user still has to agree.
Arguments
None.
Returns
Boolean.
$consent.agree()
Marks the consent as agreed.
Arguments
None.
Returns
Void.
$consent.reset()
Resets a previous agreement.
Arguments
None.
Returns
Void.
Example with all available methods
This message will keep appearing until you agree Agree This message will appear when user has already agreed Try again
Contribute
To update the build in the dist
directory:
$ gulp
To run the unit tests using the src files:
$ gulp test-src
To run the unit tests using the unminified library:
$ gulp test-dist-concatenated
To run the unit tests using the minified library:
$ gulp test-dist-minified
Change log
v2.2.0
- Added main property to package.json (#5)
v2.1.1
- Added check to make sure expires is always set correctly to fix #4
v2.1.0
- Added support for AngularJS versions older than AngularJS 1.4
v2.0.0
- Cookies are now stored for 360 days by default (instead of session)
- Added support for cookie options via
consent-cookie-options
attribute
v1.0.0
- Added support for multiple consent messages simultaneously
- Updated documentation
- Added demo
v0.1.0
- Added consent directive
- Added unit tests
- Added initial documentation