npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tilde-nlp/ngx-cookie-consent

v6.0.1

Published

Library is created so there would be single component for accepting cookies across multiple Tilde projects which use angular.

Downloads

19

Readme

ngx-cookie-consent

Library is created so there would be single component for accepting cookies across multiple Tilde projects which use angular.

Usage/Examples

Angular project

  1. Install library from npm: npm i ngx-cookie-consent.
  2. Import cookie consent module in your root module and call forRoot method passing cookie consent settings.
import {CookieConsentModule} from 'ngx-cookie-consent';
.....
@NgModule({
  imports: [
    ....
    CookieConsentModule.forRoot({show: true})
  ]
}

forRoot method adds provider for cookie consent settings and makes them injectable.

There might be cases when multiple projects are built from same repo and for one project cookie consent should be enabled, but for other it should be disabled. For such cases, you do not need to call forRoot method when importing module, but you need to create provider for CookieSettings configuration. Use specified token in app to create this provider. It is possible to change factory deps and use your own config provider.

import {CookieConsentModule, COOKIE_CONSENT_SETTINGS_TOKEN} from 'ngx-cookie-consent';
import { ConfigService } from '@ngx-config/core';

export function CookieConsentSettingsFactory(config: ConfigService): CookieConsentSettings{
    const settings = config.getSettings<CookieConsentSettings>("cookieConsent");
    return settings ?? {};
}

.....
@NgModule({
  imports: [
    ....
    CookieConsentModule,
    ....
  ],
  providers:[
    {
      provide: COOKIE_CONSENT_SETTINGS_TOKEN,
      useFactory: CookieConsentSettingsFactory,
      deps: [ConfigService]
    }
  ]
}
  1. For cookie consent to be styled, you need to use mixin and pass your theme to it and background color:
@use 'ngx-cookie-consent/src/lib/mixins/cookie-consent-theme.mixin.scss' as cookie-consent;
...
// Theme param is to make border-top in primary color and second param is used for background color
@include cookie-consent.color(your-border-top-color, your-background-color);
  1. Add CookieConsentComponent in template. Does not really matter where you put it, since it is positioned absolutely and should be displayed anyway.
<tld-cookie-consent></tld-cookie-consent>

To make cookie consent appear only if it has not been accepted, you need to check showConsent value from CookieConsentService. Use the following code:

<!-- your.component.html -->
<tld-cookie-consent *ngIf="showCookieConsent"></tld-cookie-consent>
  // your.component.ts
import { CookieConsentService } from 'ngx-cookie-consent';
....
export class YourComponent{
get showCookieConsent(){return this.cookieConsent.showConsent};
constructor(private readonly cookieConsent: CookieConsentService) {}
}

This should be enough to get cookie consent displayed and running.

Texts and translations

This package is using ngx translate - if you have it in your project then it should be straight forward, otherwise follow their documentation to get started. Translations should be put under key "COOKIE_CONSENT".

Subscribe to user action

For listening to changes, subscribe to observable provided in CookieConsentService:

// using take(1) since cookie consent should close after user action.
this.cookieConsent.cookiePreferencesChanged$
  .pipe(take(1))
  .subscribe((preferences) => {
    // Handle user action here. Enable additional cookies etc.
  });

Developer notes

This library has dependency of @ngbracket/ngx-layout which is not mentioned in package json, so there would be no errors while installing it.