Giter Club home page Giter Club logo

ngx-cookieconsent's Introduction

ngx-cookieconsent

npm version Build Status Coverage Status Known Vulnerabilities

Cookie Consent module for Angular

Demo

View the module in action at https://tinesoft.github.io/ngx-cookieconsent

Dependencies

Installation

Install Cookie Consent dependency:

npm install --save cookieconsent

// or 

yarn add cookieconsent

Now install ngx-cookieconsent via:

npm install --save ngx-cookieconsent

// or

yarn add ngx-cookieconsent

Note: If you are using Angular CLI or Nx CLI to build your app, make sure that cookieconsent is properly listed as a global library, and as global style.

To do so, edit your angular.json (or project.json for Nx CLI based apps) as such:

      "scripts": [
        "node_modules/cookieconsent/build/cookieconsent.min.js"
      ],

      "styles": [
        "node_modules/cookieconsent/build/cookieconsent.min.css"
      ],

Configuration

Prepare the config:

import {NgcCookieConsentConfig} from 'ngx-cookieconsent';

const cookieConfig:NgcCookieConsentConfig = {
  cookie: {
    domain: 'localhost' // or 'your.domain.com' // it is mandatory to set a domain, for cookies to work properly (see https://goo.gl/S2Hy2A)
  },
  palette: {
    popup: {
      background: '#000'
    },
    button: {
      background: '#f1d600'
    }
  },
  theme: 'edgeless',
  type: 'opt-out'
};

For Angular Standalone API-based apps

If you are using Angular Standalone API to bootstrap your application, you can configure the library by leveraging the new provideNgcCookieConsent(config) helper (added since v5.x.x), as such:

import {provideNgcCookieConsent} from 'ngx-cookieconsent';

//...

bootstrapApplication(AppComponent, {
  providers: [
    provideNgcCookieConsent(cookieConfig),
    // ...
  ]
});

For Angular (ng)Module-based apps

For traditional ngModule-based angular application, you need to import the library module in your application module, as such:

import {NgcCookieConsentModule} from 'ngx-cookieconsent';

//...

@NgModule({
  declarations: [AppComponent, ...],
  imports: [NgcCookieConsentModule.forRoot(cookieConfig), ...],  
  bootstrap: [AppComponent]
})
export class AppModule {
}

Other modules in your application can simply import NgcCookieConsentModule:

import {NgcCookieConsentModule} from 'ngx-cookieconsent';

@NgModule({
  declarations: [OtherComponent, ...],
  imports: [NgcCookieConsentModule, ...], 
})
export class OtherModule {
}

Usage

Inject the NgcCookieContentService in your main component (i.e. AppComponent) to show the cookie consent popup after the component is loaded. You don't need to explicitly call its init() method (done automatically when the service's constructor gets called upon instantiation By Angular).

Also, you can use the injected NgcCookieContentService to update the config (using init()), subscribe to events and do stuff like disabling cookies or other.

Here is how it works:

import { Component, OnInit, OnDestroy } from '@angular/core';
import { NgcCookieConsentService } from 'ngx-cookieconsent';
import { Subscription }   from 'rxjs';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, OnDestroy {

  //keep refs to subscriptions to be able to unsubscribe later
  private popupOpenSubscription!: Subscription;
  private popupCloseSubscription!: Subscription;
  private initializingSubscription!: Subscription;
  private initializedSubscription!: Subscription;
  private initializationErrorSubscription!: Subscription;
  private statusChangeSubscription!: Subscription;
  private revokeChoiceSubscription!: Subscription;
  private noCookieLawSubscription!: Subscription;

  constructor(private ccService: NgcCookieConsentService){}

  ngOnInit() {
    // subscribe to cookieconsent observables to react to main events
    this.popupOpenSubscription = this.ccService.popupOpen$.subscribe(
      () => {
        // you can use this.ccService.getConfig() to do stuff...
      });

    this.popupCloseSubscription = this.ccService.popupClose$.subscribe(
      () => {
        // you can use this.ccService.getConfig() to do stuff...
      });

    this.initializingSubscription = this.ccService.initializing$.subscribe(
      (event: NgcInitializingEvent) => {
        // the cookieconsent is initilializing... Not yet safe to call methods like `NgcCookieConsentService.hasAnswered()`
        console.log(`initializing: ${JSON.stringify(event)}`);
      });
    
    this.initializedSubscription = this.ccService.initialized$.subscribe(
      () => {
        // the cookieconsent has been successfully initialized.
        // It's now safe to use methods on NgcCookieConsentService that require it, like `hasAnswered()` for eg...
        console.log(`initialized: ${JSON.stringify(event)}`);
      });

    this.initializationErrorSubscription = this.ccService.initializationError$.subscribe(
      (event: NgcInitializationErrorEvent) => {
        // the cookieconsent has failed to initialize... 
        console.log(`initializationError: ${JSON.stringify(event.error?.message)}`);
      });

    this.statusChangeSubscription = this.ccService.statusChange$.subscribe(
      (event: NgcStatusChangeEvent) => {
        // you can use this.ccService.getConfig() to do stuff...
      });

    this.revokeChoiceSubscription = this.ccService.revokeChoice$.subscribe(
      () => {
        // you can use this.ccService.getConfig() to do stuff...
      });

      this.noCookieLawSubscription = this.ccService.noCookieLaw$.subscribe(
      (event: NgcNoCookieLawEvent) => {
        // you can use this.ccService.getConfig() to do stuff...
      });
  }

  ngOnDestroy() {
    // unsubscribe to cookieconsent observables to prevent memory leaks
    this.popupOpenSubscription.unsubscribe();
    this.popupCloseSubscription.unsubscribe();
    this.initializingSubscription.unsubscribe();
    this.initializedSubscription.unsubscribe();
    this.initializationErrorSubscription.unsubscribe();
    this.statusChangeSubscription.unsubscribe();
    this.revokeChoiceSubscription.unsubscribe();
    this.noCookieLawSubscription.unsubscribe();
  }
}

See Cookie Consent Documentation to see more about how to customize the UI or interact with user interactions.

I18n Support

Messages displayed in the Cookie Consent Bar can easily be translated, using libraries like ngx-translate. Basically this involved the following steps (using ngx-translate + Anglar CLI):

  • Install and configure ngx-translate

  • Provide the translation JSON files in src/assets/, for e.g: en.json, fr.json, ...

{
    "cookie": {
        "header": "Cookies used on the website!",
        "message": "This website uses cookies to ensure you get the best experience on our website.",
        "dismiss": "Got it!",
        "allow": "Allow cookies",
        "deny": "Decline",
        "link": "Learn more",
        "policy": "Cookie Policy"
    }
}

Note: see content-options.ts for complete list of messages that can be translated.

  • Configure your main component AppComponent
import { Component, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {

  constructor(private ccService: NgcCookieConsentService, private translateService:TranslateService) {
  }

  ngOnInit() {
    // Support for translated cookies messages
    this.translateService.addLangs(['en', 'fr']);
    this.translateService.setDefaultLang('en');

    const browserLang = this.translateService.getBrowserLang();
    this.translateService.use(browserLang.match(/en|fr/) ? browserLang : 'en');

    this.translateService//
      .get(['cookie.header', 'cookie.message', 'cookie.dismiss', 'cookie.allow', 'cookie.deny', 'cookie.link', 'cookie.policy'])
      .subscribe(data => {

        this.ccService.getConfig().content = this.ccService.getConfig().content || {} ;
        // Override default messages with the translated ones
        this.ccService.getConfig().content.header = data['cookie.header'];
        this.ccService.getConfig().content.message = data['cookie.message'];
        this.ccService.getConfig().content.dismiss = data['cookie.dismiss'];
        this.ccService.getConfig().content.allow = data['cookie.allow'];
        this.ccService.getConfig().content.deny = data['cookie.deny'];
        this.ccService.getConfig().content.link = data['cookie.link'];
        this.ccService.getConfig().content.policy = data['cookie.policy'];

        this.ccService.destroy(); // remove previous cookie bar (with default messages)
        this.ccService.init(this.ccService.getConfig()); // update config with translated messages
      });
  }
}

Custom Layout Support

Cookie Consent supports custom layouts, and so does ngx-cookieconsent. So if your are not happy with the default appearance of the cookie bar, you can totally customize it to better suit your needs. This involves overriding a few options:

Here is a example of a custom layout, that is inspired from the default 'basic' layout , but simply changes the message and links that are displayed in the bar.

import {NgcCookieConsentModule, NgcCookieConsentConfig} from 'ngx-cookieconsent';

const cookieConfig:NgcCookieConsentConfig = {
  cookie: {
    domain: 'localhost'// it is recommended to set your domain, for cookies to work properly
  },
  palette: {
    popup: {
      background: '#000'
    },
    button: {
      background: '#f1d600'
    }
  },
  theme: 'edgeless',
  type: 'opt-out',
  layout: 'my-custom-layout',
  layouts: {
    "my-custom-layout": '{{messagelink}}{{compliance}}'
  },
  elements:{
    messagelink: `
    <span id="cookieconsent:desc" class="cc-message">{{message}} 
      <a aria-label="learn more about cookies" tabindex="0" class="cc-link" href="{{cookiePolicyHref}}" target="_blank" rel="noopener">{{cookiePolicyLink}}</a>, 
      <a aria-label="learn more about our privacy policy" tabindex="1" class="cc-link" href="{{privacyPolicyHref}}" target="_blank" rel="noopener">{{privacyPolicyLink}}</a> and our 
      <a aria-label="learn more about our terms of service" tabindex="2" class="cc-link" href="{{tosHref}}" target="_blank" rel="noopener">{{tosLink}}</a>
    </span>
    `,
  },
  content:{
    message: 'By using our site, you acknowledge that you have read and understand our ',
    
    cookiePolicyLink: 'Cookie Policy',
    cookiePolicyHref: 'https://cookie.com',

    privacyPolicyLink: 'Privacy Policy',
    privacyPolicyHref: 'https://privacy.com',

    tosLink: 'Terms of Service',
    tosHref: 'https://tos.com',
  }
};


@NgModule({
  declarations: [AppComponent, ...],
  imports: [NgcCookieConsentModule.forRoot(cookieConfig), ...],  
  bootstrap: [AppComponent]
})
export class AppModule {
}

Compatibility with Angular

Every Nx plugin relies on the underlying Nx Workspace/DevKit it runs on. This table provides the compatibility matrix between major versions of Nx workspace and this plugin.

Library Version Angular version
>=v6.0.0 >=v16.x.x
>=v5.0.0 >=v15.x.x
>=v4.0.1 >=v14.x.x
v3.0.1 >=v12.x.x
>=v2.2.3 >=v6.x.x
v1.1.0 <v6.x.x

Credits

ngx-cookieconsent is built upon Cookie Consent, by Osano

License

Copyright (c) 2018-present Tine Kondo. Licensed under the MIT License (MIT)

ngx-cookieconsent's People

Contributors

azure-pipelines[bot] avatar colinodell avatar damianszczepanik avatar dependabot[bot] avatar greenkeeper[bot] avatar jcb-entrnce avatar johnnyqqqq avatar mrtnbroder avatar nlueg avatar nolanus avatar semantic-release-bot avatar tinesoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ngx-cookieconsent's Issues

this.ccService.initialize$ subscription doesn't work

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version: ^3.1.0
- ngx-cookieconsent version: ^2.2.0

OS Version?

Windows 10.

Angular, Node and al Versions?

Angular CLI: 7.3.6
Node: 11.3.0
OS: win32 x64
Angular: 7.2.10

Repro steps

  • install ngx-cookieconsent according to README
  • Put subscribers to ngOnInt function
  • Add the following code to
 this.initializeSubscription = this.ccService.initialize$.subscribe(
      (event: NgcInitializeEvent) => {
        console.table(event); // Doesn't fire 
      },
    );

Desired functionality

After page refresh or open the page again in a different tab I expect that I will see in a console
an event object with STATUS: accept, decline or dismiss

Not working with universal (angular 6+)

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

OS and Version?

macOS High Sierra

Versions

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 6.0.3
Node: 8.11.3
OS: darwin x64
Angular: 6.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.3
@angular-devkit/build-angular     0.6.3
@angular-devkit/build-optimizer   0.6.3
@angular-devkit/core              0.6.3
@angular-devkit/schematics        0.6.3
@angular/cdk                      6.1.0
@angular/cli                      6.0.3
@angular/flex-layout              6.0.0-beta.16
@angular/material                 6.1.0
@angular/platform-server          6.0.3
@ngtools/webpack                  6.0.3
@schematics/angular               0.6.3
@schematics/update                0.6.3
rxjs                              6.2.0
typescript                        2.7.2
webpack                           4.8.3

Mention any other details that might be useful

It's not working with universal. I've seen similar issues with other modules.
This could help... valor-software/ngx-bootstrap#2369 (comment)

NgcContentOptions class missing policy attribute

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

OS and Version?

OS independent bug

Versions

Angular CLI: 6.2.1
Node: 10.8.0
OS: win32 x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.7.5
@angular-devkit/build-angular 0.7.5
@angular-devkit/build-optimizer 0.7.5
@angular-devkit/build-webpack 0.7.5
@angular-devkit/core 0.7.5
@angular-devkit/schematics 0.8.1
@angular/cli 6.2.1
@ngtools/webpack 6.1.5
@schematics/angular 0.8.1
@schematics/update 0.8.1
rxjs 6.3.2
typescript 2.7.2
webpack 4.9.2

Repro steps

Add

content: {
policy: "Anything other than Cookie Policy"
}

to NgcCookieConsentConfig.

The log given by the failure

ERROR in src/app/app.module.ts(72,5): error TS2322: Type '{ cookie: { domain: string; }; position: "bottom-left"; theme: "block"; palette: { popup: { backg...' is not assignable to type 'NgcCookieConsentConfig'.
Types of property 'content' are incompatible.
Type '{ message: string; allow: string; deny: string; link: string; href: string; policy: string; }' is not assignable to type 'NgcContentOptions'.
Object literal may only specify known properties, and 'policy' does not exist in type 'NgcContentOptions'.

Desired functionality

Being able to change policy text and NgcContentOptions class having this property.

Mention any other details that might be useful

If policy text was not meant to be changed, this might be a feature request, but since original cookie consent gives the option to do this, I thought it is a bug that this has not been implemented.
It is useful to have this option especially for non-english websites.

Adding the policy content actually ran as expected, but it gives error since it is not recognized on NgcContentOptions class.

Cookie notification showing up after every refresh (IE)

Bug Report or Feature Request (mark with an x)

- [x ] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version: 3.1.0
- ngx-cookieconsent version: 2.1.1

OS Version?

Windows 10

Angular and Node versions

- Angular CLI: 7.3.6
- Node: 8.11.3  
- Angular: 7.2.9   

Repro steps

Exactly the same as https://github.com/insites/cookieconsent/issues/139 but for ngx-cookieconsent rather than cookieconsent. However, ignoreDoNotTrack is not a property of NgcCookieConsentConfig and so I cannot apply the same fix.

Always shows in angular universal

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

It always shows in angular universal. In the browser version works correctly, but not sure if it needs to be added in a different way when using angular universal. My guess is that the server is rendering it and showing it, even when the user has already accepted it. Any possible solution?

Interface indexes fail to compile

Bug Report or Feature Request

- [x] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version: 3.1.0
- ngx-cookieconsent version: 2.2.0

OS Version?

Windows 10

Angular, Node and al Versions?

Angular CLI: 6.2.1
Node: 11.10.0
OS: win32 x64
Angular: 6.1.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

@angular-devkit/architect         0.8.1
@angular-devkit/build-angular     0.8.1
@angular-devkit/build-optimizer   0.8.1
@angular-devkit/build-webpack     0.8.1
@angular-devkit/core              0.8.1
@angular-devkit/schematics        0.8.1
@angular/cdk                      6.4.7
@angular/cli                      6.2.1
@angular/flex-layout              6.0.0-beta.18
@angular/material                 6.4.7
@angular/pwa                      0.8.1
@ngtools/webpack                  6.2.1
@schematics/angular               0.8.1
@schematics/update                0.8.1
rxjs                              6.3.1
typescript                        2.9.2
webpack                           4.17.3

Repro steps

  • yarn add ngx-cookieconsent
  • ng serve

The log given by the failure

ERROR in node_modules/ngx-cookieconsent/model/content-options.d.ts(7,5): error TS2411:
Property 'header' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/content-options.d.ts(8,5): error TS2411: Property
'message' of type 'string | undefined' is not assignable to string index type 'string'.node_modules/ngx-cookieconsent/model/content-options.d.ts(9,5): error TS2411: Property
'dismiss' of type 'string | undefined' is not assignable to string index type 'string'.node_modules/ngx-cookieconsent/model/content-options.d.ts(10,5): error TS2411: Property 'allow' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/content-options.d.ts(11,5): error TS2411: Property 'deny' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/content-options.d.ts(12,5): error TS2411: Property 'link' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/content-options.d.ts(13,5): error TS2411: Property 'href' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/content-options.d.ts(14,5): error TS2411: Property 'close' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/content-options.d.ts(15,5): error TS2411: Property 'policy' of type 'string | undefined' is not assignable to string index type 'string'.node_modules/ngx-cookieconsent/model/content-options.d.ts(16,5): error TS2411: Property 'target' of type 'string | undefined' is not assignable to string index type 'string'.node_modules/ngx-cookieconsent/model/html-elements.d.ts(5,5): error TS2411: Property 'header' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/html-elements.d.ts(6,5): error TS2411: Property 'message' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/html-elements.d.ts(7,5): error TS2411: Property 'messagelink' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/html-elements.d.ts(8,5): error TS2411: Property 'dismiss' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/html-elements.d.ts(9,5): error TS2411: Property 'allow' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/html-elements.d.ts(10,5): error TS2411: Property 'deny' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/html-elements.d.ts(11,5): error TS2411: Property 'link' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/ngx-cookieconsent/model/html-elements.d.ts(12,5): error TS2411: Property 'close' of type 'string | undefined' is not assignable to string index type 'string'.

Desired functionality

The compilation step succeeds

Mention any other details that might be useful

The issue is resolved by changing the typescript index to string | undefined to account for optional properties in the interfaces

Cannot set property 'onPopupOpen' of null

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version: 3.1.1
- ngx-cookieconsent version: 2.2.3

OS Version?

Windows 10 but in my opinion it doesn't matter

Angular, Node and al Versions?

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/

Angular CLI: 9.0.7
Node: 12.6.0
OS: win32 x64

Angular: 9.0.7
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.900.7
@angular-devkit/build-angular 0.900.7
@angular-devkit/build-optimizer 0.900.7
@angular-devkit/build-webpack 0.900.7
@angular-devkit/core 9.0.7
@angular-devkit/schematics 9.0.7
@angular/cdk 9.1.3
@angular/material 9.1.3
@angular/pwa 0.900.7
@ngtools/webpack 9.0.7
@schematics/angular 9.0.7
@schematics/update 0.900.7
rxjs 6.5.4
typescript 3.7.5
webpack 4.41.2

Repro steps

I have to show cookie information when user is logged in and doesn't approve NDA Terms.

AppModule

@NgModule({
  imports: [
    NgProgressModule,
    BrowserAnimationsModule,
    BrowserModule,
    AuthModule,
    CoreModule,
    SharedModule,
    ModuleRouting,
    ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }),
    NgcCookieConsentModule.forRoot(null),
  ],
  declarations: [
    AppComponent,
    ToolbarComponent,
  ],
  bootstrap: [
    AppComponent,
  ],
})
export class AppModule { }

Note: I have to set null as config because in other way Cookie information is shown.

Next in toolbar component I have a function which show cookies information.

ToolbarComponent

this.ccService.initialize$
      .pipe(untilDestroyed(this))
      .subscribe(() => {
        this.visibleCookies = true;
      });

    this.ccService.init(this.getCookieConfig());

    this.ccService.statusChange$
      .pipe(untilDestroyed(this))
      .subscribe((event: NgcStatusChangeEvent) => {
        if (event.status === 'allow') {
          this.currentUserService.setApprovedCookies()
            .pipe(untilDestroyed(this))
            .subscribe();
        }
      });

The log given by the failure

core.js:6185 ERROR TypeError: Cannot set property 'onPopupOpen' of null
    at NgcCookieConsentService.init (ngx-cookieconsent.js:119)
    at new NgcCookieConsentService (ngx-cookieconsent.js:97)
    at Object.NgcCookieConsentService_Factory [as factory] (ngx-cookieconsent.js:234)
    at R3Injector.hydrate (core.js:16865)
    at R3Injector.get (core.js:16617)
    at NgModuleRef$1.get (core.js:36027)
    at Object.get (core.js:33779)
    at getOrCreateInjectable (core.js:5805)
    at ɵɵdirectiveInject (core.js:20861)
    at NodeInjectorFactory.ToolbarComponent_Factory

Desired functionality

I would like to import NgcCookieConsentModule without config and be able to show cookies information when I need.

Correct configuration delivery (translations)

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

OS and Version?

Windows 10

Versions

Angular 4.2.4

Desired functionality

I use translation service inside my Angular app. I have a problem with delivery of translations to ngx-cookieconsent configuration. Is there any way to pass configuration object later, inside component? I see it's required to initialize module, but It's odd to pass translation from the module level. I mean:

NgcCookieConsentModule.forRoot(cookieConfig)

I have to have translations already here, but I have it only in a component - they come from a service.

Would be awesome to abstract out messages from configuration object to make it translateable.

.initialize$ callback is never called

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

OS and Version?

macOS High Sierra. Version 10.13.6

Versions

Output from: ng --version, in case you are using Angular CLI.
Angular CLI: 6.1.5
Node: 8.9.4
OS: darwin x64
Angular: 6.1.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.7.5
@angular-devkit/build-angular 0.7.5
@angular-devkit/build-optimizer 0.7.5
@angular-devkit/build-webpack 0.7.5
@angular-devkit/core 0.7.5
@angular-devkit/schematics 0.7.5
@angular/cli 6.1.5
@ngtools/webpack 6.1.5
@schematics/angular 0.7.5
@schematics/update 0.7.5
rxjs 6.3.3
typescript 2.7.2
webpack 4.9.2

Repro steps

I followed the exact instructions given in the readme and it works great! I can see the consent popup, I can open it, close it, allow cookies, decline etc.
However, I never see the .initialize$ callback is never called. Why is that?
I wanted to use event.status to access the current status of the consent but nothing is happening (no error message either).

this.initializeSubscription = this.ccService.initialize$.subscribe(
(event: NgcInitializeEvent) => {
console.log('init');
// you can use this.ccService.getConfig() to do stuff...
});

The log given by the failure

No failure. The .initialize$ just doesn't fire up

Desired functionality

.initialize$ to work
or find a way to access the current status of the consent. Alternatively, I will access the consent cookie directly.

Mention any other details that might be useful

Cannot read property 'initialise' of undefined in angular universal 10

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version: 3.1.1
- ngx-cookieconsent version: 2.2.3

OS Version?

Windows 10

Angular, Node and al Versions?

Angular CLI: 10.0.3
Node: 14.5.0
OS: win32 x64
Angular: 10.0.4
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, platform-server, router
Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.1000.3
@angular-devkit/build-angular 0.1000.3
@angular-devkit/build-optimizer 0.1000.3
@angular-devkit/build-webpack 0.1000.3
@angular-devkit/core 10.0.3
@angular-devkit/schematics 10.0.3
@angular/cdk 10.1.3
@angular/cli 10.0.3
@ngtools/webpack 10.0.3
@nguniversal/builders 10.0.1
@nguniversal/common 10.0.1
@nguniversal/express-engine 10.0.1
@nguniversal/module-map-ngfactory-loader 8.2.6
@schematics/angular 10.0.3
@schematics/update 0.1000.3
rxjs 6.6.0
typescript 3.9.7
webpack 4.43.0

Repro steps

npm run build:ssr && npm run serve:ssr
Where:
"serve:ssr": "node dist/compy/server/main.js",
"build:ssr": "ng build --prod && ng run compy:server:production",

The log given by the failure

Node Express server listening on http://localhost:4000
ERROR TypeError: Cannot read property 'initialise' of undefined
at NgcCookieConsentService.init (C:\Coding\compyFront\dist\compy\server\main.js:1:3482889)
at new NgcCookieConsentService (C:\Coding\compyFront\dist\compy\server\main.js:1:3482119)
at Object.NgcCookieConsentService_Factory [as factory] (C:\Coding\compyFront\dist\compy\server\main.js:1:3484065)
at R3Injector.hydrate (C:\Coding\compyFront\dist\compy\server\main.js:1:2802301)
at R3Injector.get (C:\Coding\compyFront\dist\compy\server\main.js:1:2799033)
at NgModuleRef$1.get (C:\Coding\compyFront\dist\compy\server\main.js:1:2977443)
at Object.get (C:\Coding\compyFront\dist\compy\server\main.js:1:2946537)
at getOrCreateInjectable (C:\Coding\compyFront\dist\compy\server\main.js:1:2713691)
at Module.ɵɵdirectiveInject (C:\Coding\compyFront\dist\compy\server\main.js:1:2832947)
at NodeInjectorFactory.AppComponent_Factory [as factory] (C:\Coding\compyFront\dist\compy\server\main.js:1:1694986)

Desired functionality

I would like to run it without any problem in angular universal (server side rendering), since it is running perfect in regular angular.

Mention any other details that might be useful

It works great in regular app, but fail in universal angular app, so i think it is mainly due to trying to open up a window o dialog when running in server side mode. Or the other, it is possible that some way i need to add it in other places apart of angular.json config file.
Please any file you need just tell me , i just can not post entire project since it is private, but i can delivery single files without issue.
Thanks in advance.

Linting issue blocking compile

I am using

  • cookie consent 3.0.6
  • ngx-cookie-consent 1.0.1
  • angular 5
  • angular-cli 1.7.4
  • typescript 2.6.2
  • tried tslint 3.7.0 and 3.80
    and couldn't seem to get this to compile.

I get this error on build that blocks compile. Any ideas?

ERROR in node_modules/ngx-cookieconsent/model/common-interfaces.d.ts(35,5): error TS2411: Property 'allow' of type '"allow" | undefined' is not assignable to string index type '"allow" | "deny" | "dismiss"'. node_modules/ngx-cookieconsent/model/common-interfaces.d.ts(36,5): error TS2411: Property 'deny' of type '"deny" | undefined' is not assignable to string index type '"allow" | "deny" | "dismiss"'. node_modules/ngx-cookieconsent/model/common-interfaces.d.ts(37,5): error TS2411: Property 'dismiss' of type '"dismiss" | undefined' is not assignable to string index type '"allow" | "deny" | "dismiss"'.

No Angular routing possible

The link provided in NgcContentOptions does not allow Angular router to be used, sadly...
As such, a local redirection reloads the complete Angular app which is not an expected behaviour.
Would you think of adding such possibility to use routerLink?
Thanks

Undefined Error in Internet Explorer - Unable to get property 'initialise'

Bug Report or Feature Request

  • bug report (I searched the issues)

CookieConsent and Library Versions?

  • cookieconsent version: 3.1.0
  • ngx-cookieconsent version: 2.0.0

OS Version?

Windows 7

Angular, Node and al Versions?

Angular CLI: 7.0.7
Node: 10.3.0
Angular: 7.0.4

Repro steps

Open http://localhost:4200/ in Internet Explorer 10 or Edge

The log given by the failure

Error: Operation failed. undefined : undefinedError: Uncaught (in promise): TypeError: Unable to get property 'initialise' of undefined or null reference
TypeError: Unable to get property 'initialise' of undefined or null reference
at NgcCookieConsentService.prototype.init (http://localhost:4200/vendor.js:76077:13)
at NgcCookieConsentService (http://localhost:4200/vendor.js:76024:9)
at _createClass (http://localhost:4200/vendor.js:52257:13)
at createProviderInstance (http://localhost:4200/vendor.js:52227:13)
at resolveNgModuleDep (http://localhost:4200/vendor.js:52190:17)
at NgModuleRef
.prototype.get (http://localhost:4200/vendor.js:52899:9)
at resolveDep (http://localhost:4200/vendor.js:53270:5)
at createClass (http://localhost:4200/vendor.js:53142:13)
at createDirectiveInstance (http://localhost:4200/vendor.js:53021:5)
at createViewNodes (http://localhost:4200/vendor.js:54247:21)

Desired functionality

To know what configuration settings we might have wrongly set.

Many thanks.

How to implement using only webpack builder and Angular 4

Hello,

I'm trying to implement this package using webpack only. My project is building using only this way to build. Can you give some instruction how to do it? I'm trying to add the scripts in _Layout or main app component but the result is:

AppComponent_Host.html:1 ERROR TypeError: Cannot read property 'initialise' of undefined
at NgcCookieConsentService.init (cookieconsent.service.js:53)
at new NgcCookieConsentService (cookieconsent.service.js:23)
at _createClass (core.es5.js:9532)
at createProviderInstance$1 (core.es5.js:9500)
at resolveNgModuleDep (core.es5.js:9485)
at NgModuleRef
.get (core.es5.js:10577)
at resolveDep (core.es5.js:11080)
at createClass (core.es5.js:10944)
at createDirectiveInstance (core.es5.js:10764)
at createViewNodes (core.es5.js:12212)

Thank you,
Gettaxsolutions team

Demo site cannot be run locally

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

OS Version?

macOS Mojave

Angular, Node and al Versions?

Angular CLI: 7.3.8
Node: 10.15.0
OS: darwin x64
Angular: 7.2.14

Repro steps

After I've cloned the repo, installed dependencies (npm install), built demo app (npm run demo) and run demo app (cd demo/dist && ngserve), it fails with error.

The log given by the failure

ERROR in /Users/mightymatth/.nvm/versions/node/v10.15.0/lib/node_modules/ngx-cookieconsent/esm5/ngx-cookieconsent.es5.js
Module not found: Error: Can't resolve 'rxjs' in '/Users/mightymatth/.nvm/versions/node/v10.15.0/lib/node_modules/ngx-cookieconsent/esm5'

Desired functionality

It should successfully serve demo application.

Cannot read property 'palette' of null

Hi,

Thank you for your lib!

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> 'Cannot read property 'palette' of null'

### CookieConsent and Library Versions?

 "cookieconsent": "^3.1.1",
 "ngx-cookieconsent": "^2.2.3",

OS Version?

browser Chrome Mobile 77.0.3865

Angular, Node and al Versions?

angular 9

Repro steps

Bug: 'Cannot read property 'palette' of null'
Cannot reproduce locally but is happening for some user on prod
This is happening either when:
this.ccService.destroy(); high chance this is happening on this line
or
this.ccService.init(this.ccService.getConfig()); low chance it is happening on this line

The log given by the failure

Node.removeChild(s),e.customStyles[n]=null}}}(this.options.palette),this.options=null},o.prototype.open=function(t){if(this.element)return t {snip}

Desired functionality

No crash

Mention any other details that might be useful

in my setup i have:
const cookieConfig: NgcCookieConsentConfig = {
cookie: {
domain: environment.domain
},
palette: {
popup: {
background: '#012E4B'
},
button: {
background: '#33B4A5'
}
},
theme: 'edgeless'
};

Update npm version of your project

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [X ] feature request

CookieConsent and Library Versions?

- cookieconsent version: 3.1.0
- ngx-cookieconsent version: 2.0.0

OS Version?

Windows 10

Angular, Node and al Versions?

Angular CLI: 7.0.5
Node: 9.11.1
OS: win32 x64
Angular: 7.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.10.5
@angular-devkit/build-angular 0.11.4
@angular-devkit/build-optimizer 0.11.4
@angular-devkit/build-webpack 0.11.4
@angular-devkit/core 7.0.5
@angular-devkit/schematics 7.0.5
@angular/cdk 7.0.4
@angular/cli 7.0.5
@angular/material 7.0.4
@angular/platform-server 7.0.4
@ngtools/webpack 7.1.4
@schematics/angular 7.0.5
@schematics/update 0.10.5
rxjs 6.3.3
typescript 3.1.6
webpack 4.23.1

Repro steps

The log given by the failure

Desired functionality

Could you update npm version of your project?
Actually, github is in 2.1.0 version but npm is in 2.0.0

Mention any other details that might be useful

Update for Angular 6

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

OS and Version?

Windows 7

Versions

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 6.0.8
Node: 8.11.3
OS: win32 x64
Angular: 6.0.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cli                      6.0.8
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.2.1
typescript                        2.7.2
webpack                           4.8.3
ngx-cookieconsent                 1.0.1

Repro steps

Simply follow the documentation to include it in your application using angular-cli.

The log given by the failure

ERROR in ./node_modules/ngx-cookieconsent/service/cookieconsent.service.js
Module not found: Error: Can't resolve 'rxjs/Subject' in 'my\project\here\node_modules\ngx-cookieconsent\service'

Desired functionality

No compiler error.

Mention any other details that might be useful

I assume this is due to the changes paths in RxJs 6 that is used together with Angular 6.

Replace karma by jest to run tests

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x ] feature request

Desired functionality

Replace karma by jest to run test

Mention any other details that might be useful

How to:

  • edit .yo-rc.json and add/change "testingFramework": "jest"
  • edit .yo-rc.json and remove karma related files (config/karma.conf) from "exclusions" and "deleteExclusions" arrays
  • run yo ngx-library
  • test with gulp test

How to check consent status?

Hi,

Once I've clicked on "Allow" I can see in my cookies that I got the cookie set to "allow".
But I'm not able to check cookie status in the app. I've tried with

this.ccService.getStatus()

but all it shows is
{deny: "deny", allow: "allow", dismiss: "dismiss"}

How can I check cookie consent status in the rest of my app? Do I have to check in the cookies by my own or can I use your library?
Thx

TypeError: Cannot read property 'initialise' of undefined - only in production

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version: ^3.1.1
- ngx-cookieconsent version:^2.2.3"

OS Version?

macOS.Catalina

Angular, Node and al Versions?

Angular CLI: 9.1.8
Node: 10.15.3
OS: darwin x64

Angular: 9.1.11
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.901.8
@angular-devkit/build-angular 0.901.8
@angular-devkit/build-optimizer 0.901.8
@angular-devkit/build-webpack 0.901.8
@angular-devkit/core 9.1.8
@angular-devkit/schematics 9.1.8
@angular/cdk 9.2.4
@angular/cli 9.1.8
@angular/material 9.2.4
@ngtools/webpack 9.1.8
@schematics/angular 9.1.8
@schematics/update 0.901.8
rxjs 6.5.5
typescript 3.8.3
webpack 4.42.0

Repro steps

The log given by the failure

vendor.js:1 ERROR TypeError: Cannot read property 'initialise' of undefined
at t.init (vendor.js:1)
at new t (vendor.js:1)
at Object.t.ɵfac [as factory] (vendor.js:1)
at t.hydrate (vendor.js:1)
at t.get (vendor.js:1)
at e.get (vendor.js:1)
at Object.get (vendor.js:1)
at pn (vendor.js:1)
at Object.$o (vendor.js:1)
at Object.e.ɵfac [as factory] (main.js:1)

Mention any other details that might be useful

If I run ng serve the application will be displayed correctly.
This error only happens in production, when running
ng build --aot --prod --build-optimizer=true --vendor-chunk=true --output-hashing=none

This is from my angular.json so you can verify that the js files are linkes correctly:

        "styles": [
          "src/assets/styles/styles.css",
          "./node_modules/cookieconsent/build/cookieconsent.min.css"
        ],
        "scripts": [
          "./node_modules/cookieconsent/build/cookieconsent.min.js"
        ],

Usage of i18nsupport AND custom-layout at the same time

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

CookieConsent and Library Versions?

- cookieconsent version: 3.1.1
- ngx-cookieconsent version: 2.2.3

OS Version?

macOs - Catalina

Angular, Node and al Versions?

Angular CLI: 9.1.1
Node: 12.16.1
Angular: 9.1.2

Repro steps

The log given by the failure

Desired functionality

I need to use both the functionality for i18n - translations as well as a custom layout - but I really can't figure out how to solve this. This is since the site i'm building for need support for both swedish and english in this case and the ux-designers have made a mock that needs the usage of custom layout-functionality.

Mention any other details that might be useful

Default values show for few seconds in content in slow networks.

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

OS and Version?

Mac - High Sierra

Versions

Angular CLI: 1.7.4
Node: 8.9.4
Angular: 4.4.7

Repro steps

1.  Change the default text in the content.
2. Change network speed to 3g from chrome networks tab.
3. Reload the page and the cookie consent default value is shown for few seconds before the translation changes appear
4. How I fixed this is with a simple hack - 
* In AppModule config for cookie consent, I used autoOpen: false
* In AppComponent ngOnInit method I used this - 
    this.translate.get(['cookie.header', 'cookie.message', 'cookie.dismiss', 'cookie.allow', 'cookie.deny', 'cookie.link']).subscribe(data => {

        this.ccService.getConfig().content = this.ccService.getConfig().content || {} ;
        // Override default messages with the translated ones
        this.ccService.getConfig().content.header = data['cookie.header'];
        this.ccService.getConfig().content.message = data['cookie.message'];
        this.ccService.getConfig().content.dismiss = data['cookie.dismiss'];
        this.ccService.getConfig().content.allow = data['cookie.allow'];
        this.ccService.getConfig().content.deny = data['cookie.deny'];
        this.ccService.getConfig().content.link = data['cookie.link'];

        this.ccService.init(this.ccService.getConfig());
        if (!this.ccService.hasConsented())
          this.ccService.open();
        else
          this.ccService.destroy();
      });

The log given by the failure

Desired functionality

The cookie consent should show the custom content only but not the default values. This leads to bad experience for slow networks.

Mention any other details that might be useful

initialize$ stream never called

Bug Report

The initialize$ stream is never called. I think this is coming from the init method in NgcCookieConsentService declaring this.config.onInitialize whereas the callback hook in cookieconsent.js is onInitialise (with an 's' not a 'z'). I fixed this locally and the callback seems to be working correctly now.

Once user click on GOT IT button popup should Hide

CookieConsent and Library Versions?

- cookieconsent version: 3.1.1
- ngx-cookieconsent version: 2.2.3

OS Version?

win : 10

Angular CLI: 8.1.1
Node: 12.2.0
OS: win32 x64
Angular: 8.1.1

Desired functionality

I want to hide cookie popup permanently when user click on got it button. I mean popup wont show to that user ever again. I like storing some value in cookie and then show popup based on that value. Some thing like that.

I am not sure how to achieve this.

NgcHTMLElements won't be updated

Bug Report

- [X] bug report -> please search issues before submitting
- [ ] feature request

Versions

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 6.0.8
Node: 10.5.0
OS: darwin x64
Angular: 6.0.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.8
@angular-devkit/build-angular     0.6.8
@angular-devkit/build-optimizer   0.6.8
@angular-devkit/core              0.6.8
@angular-devkit/schematics        0.6.8
@angular/cli                      6.0.8
@ngtools/webpack                  6.0.8
@schematics/angular               0.6.8
@schematics/update                0.6.8
rxjs                              6.2.1
typescript                        2.7.2
webpack                           4.8.3

Report

if i try to change for example the link-element (remove of the target-element)
<a aria-label="learn more about cookies" class="cc-link" href="{{href}}">{{link}}</a>
the configuration is updated as desired but the output is still the same
<a aria-label="learn more about cookies" class="cc-link" href="{{href}}" target="_blank">{{link}}</a>

How can this be achieved?

Is it possible to include multiple links and insert them in the middle of a sentence?

I searched through the documentation but cannot find the answers to the following questions.

Question 1: Is it possible to have more than one links?

Question 2: Is it possible to insert the link in the middle of a sentence instead of at the end by default?

Default:

This website use cookies to ensure you get the best experience on our website. Privacy Policy

What I want:

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.

Is it possible?

Thank you.

Multi Domain Support

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version:
- ngx-cookieconsent version:

OS Version?

Angular, Node and al Versions?

Repro steps

The log given by the failure

Desired functionality

Mention any other details that might be useful

I have two domains rajeshyadav.net and rajeshkumaryadav.com in the domain I set .com site which works fine but when I open .net site I click got it and refresh page again it shows, can we pass two domains ?

Missing export of `NgcCookieOptions`

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version:        3.1.1
- ngx-cookieconsent version:    2.2.1

OS Version?

Windows 10

Angular, Node and al Versions?

Angular CLI: 7.3.9
Node: 10.15.3
OS: win32 x64
Angular: 7.2.15

@angular-devkit/architect 0.13.9
@angular-devkit/build-angular 0.13.9
@angular-devkit/build-optimizer 0.13.9
@angular-devkit/build-webpack 0.13.9
@angular-devkit/core 7.3.9
@angular-devkit/schematics 7.3.9
@angular/cli 7.3.9
@ngtools/webpack 7.3.9
@schematics/angular 7.3.9
@schematics/update 0.13.9
rxjs 6.3.3
typescript 3.2.4
webpack 4.29.0

npm 6.4.1

Repro steps

  • try to import and use NgcCookieOptions like
    import { NgcCookieOptions } from 'ngx-cookieconsent';

  • adding NgcCookieOptions to the export statement of index.ts fixes the compiler errors but during runtime it turns out that it could not be found

The log given by the failure

Compiler error before adding to export statement:

ERROR in src/app/app.component.ts(4,54): error TS2724: Module '"<project_root>/node_modules/ngx-cookieconsent/ngx-cookieconsent"' has no exported member 'NgcCookieOptions'

While running the application

WARNING in ./src/app/app.component.ts 23:52-68
"export 'NgcCookieOptions' was not found in 'ngx-cookieconsent'

Error displayed in Chrome:

ERROR TypeError: Cannot read property 'initialise' of undefined
at NgcCookieConsentService.push../node_modules/ngx-cookieconsent/esm5/ngx-cookieconsent.es5.js.NgcCookieConsentService.init (ngx-cookieconsent.es5.js:149)
at new NgcCookieConsentService (ngx-cookieconsent.es5.js:96)
at createClass (core.js:21265)
at createProviderInstance (core.js:21235)
at resolveNgModuleDep (core.js:21199)
at NgModuleRef
.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef
.get (core.js:21907)
at resolveDep (core.js:22278)
at createClass (core.js:22152)
at createDirectiveInstance (core.js:22029)
at createViewNodes (core.js:23255)

Desired functionality

NgcCookieOptions should be exported

Cannot read property 'initialise' of undefined at NgcCookieConsentService.push

I was able to get ngx-cookieconsent v1.1.0 to work with Angular 5.2.X but after updating my project to Angular 7.2.0 and ngx-cookieconsent/cookieconsent to the latest version I am unable to get it to work.

My project is using

Angular 7.2.0
Node 9.1.0
ngx-cookieconsent 2.1.1
cookieconsent 3.1.0

Angular-cli.json:

"scripts": [
        "../node_modules/cookieconsent/build/cookieconsent.min.js"
      ],

      "styles": [
        "../node_modules/cookieconsent/build/cookieconsent.min.css"
      ],

App.Module

`import {NgcCookieConsentModule, NgcCookieConsentConfig} from 'ngx-cookieconsent';
 NgcCookieConsentModule.forRoot(cookieConfig),
`

Error 1:

ERROR TypeError: Cannot read property 'initialise' of undefined
at NgcCookieConsentService.push../node_modules/ngx-cookieconsent/esm5/ngx-cookieconsent.es5.js.NgcCookieConsentService.init (ngx-cookieconsent.es5.js:149)
at new NgcCookieConsentService (ngx-cookieconsent.es5.js:96)
at createClass (core.js:21264)
at createProviderInstance (core.js:21234)
at resolveNgModuleDep (core.js:21198)
at NgModuleRef
.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef
.get (core.js:21906)
at resolveDep (core.js:22277)
at createClass (core.js:22157)
at createDirectiveInstance (core.js:22028)
at createViewNodes (core.js:23254)

Error 2:

ERROR CONTEXT AppComponent_Host.ngfactory.js? [sm]:1

Error 3:

main.ts:17 TypeError: Cannot read property 'initialise' of undefined
at NgcCookieConsentService.push../node_modules/ngx-cookieconsent/esm5/ngx-cookieconsent.es5.js.NgcCookieConsentService.init (ngx-cookieconsent.es5.js:149)
at new NgcCookieConsentService (ngx-cookieconsent.es5.js:96)
at createClass (core.js:21264)
at createProviderInstance (core.js:21234)
at resolveNgModuleDep (core.js:21198)
at NgModuleRef
.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef
.get (core.js:21906)
at resolveDep (core.js:22277)
at createClass (core.js:22157)
at createDirectiveInstance (core.js:22028)
at createViewNodes (core.js:23254)

Does this library write a cookie?

I am using angular 7.2 and have installed nix-cookieconsent following the guide https://tinesoft.github.io/ngx-cookieconsent/doc/index.html

Is this library supposed to write a cookie or do I have to do it? If I have to write it, I guess I need to listen to the statusChangeSubscription event.

 const cookieConfig: NgcCookieConsentConfig = {
  cookie: {
    domain: 'mingenoptraening.dk'
  },
  position: 'bottom',
  theme: 'classic',
  palette: {
    popup: {
      background: '#000000',
      text: '#ffffff',
      link: '#ffffff'
    },
    button: {
      background: '#f1d600',
      text: '#000000',
      border: 'transparent'
    }
  },
  type: 'opt-in',
  content: {
    message: 'Fritvalgservice bruger cookies for at give dig en bedre oplevelse.',
    deny: 'Brug ikke cookies.',
    allow: 'Tillad cookies',
    link: 'Læs om vores cookie politik',
    href: 'https://fritvalgservice.dk/om-fritvalgservice/',
    policy: 'Cookie Policy'
  }
};

image

Problem with rxjs 6.4.0

Trying to add in project with rxjs 6.4.3 and the component version 1.1.1 fail:
ERROR in ./node_modules/rxjs/Subject.js

Module not found: Error: Can't resolve 'rxjs-compat/Subject' in 'D:\Projects\TFS\GetTaxSolutions\GTS_Angular\GetTaxSolutions.Web\node_modules\rxjs'
@ ./node_modules/rxjs/Subject.js 6:9-39
@ ./node_modules/ngx-cookieconsent/service/cookieconsent.service.js
@ ./ClientApp/app/app.module.server.ngfactory.js
@ ./ClientApp/boot.server.PRODUCTION.ts

Karma unit test - Failed: Cannot read property 'initialise' of undefined

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

OS and Version?

macOS Mojave

Versions

Angular CLI: 6.2.7
Node: 8.11.2
OS: darwin x64
Angular: 6.1.9
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router
... service-worker

Package Version

@angular-devkit/architect 0.8.4
@angular-devkit/build-angular 0.10.6
@angular-devkit/build-ng-packagr 0.8.4
@angular-devkit/build-optimizer 0.10.6
@angular-devkit/build-webpack 0.10.6
@angular-devkit/core 0.8.4
@angular-devkit/schematics 0.8.7
@angular/cdk 6.4.7
@angular/cli 6.2.7
@ngtools/json-schema 1.1.0
@ngtools/webpack 7.0.6
@schematics/angular 0.8.7
@schematics/update 0.8.7
ng-packagr 4.2.0
rxjs 6.3.3
typescript 2.7.2
webpack 4.19.1

Repro steps

I have included the library following the steps without any problem, but when I try to make a unit test the following error ocurs:

My test is:

const cookieConfig: NgcCookieConsentConfig = {
  cookie: {
    domain: 'localhost'
  }
};
fdescribe('HeaderComponent', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [
        ...
        NgcCookieConsentModule.forRoot(cookieConfig)],
      providers: [
        ...
        {provide: APP_BASE_HREF, useValue: '/'}
      ]
    });
  });

  it('should create the app', async(() => {
    const fixture = TestBed.createComponent(HeaderComponent);
    const app = fixture.debugElement.componentInstance;
    expect(app).toBeTruthy();
  }));
});

The log given by the failure

Failed: Cannot read property 'initialise' of undefined
error properties: Object({ ngDebugContext: DebugContext_({ view: Object({ def: Object({ factory: Function, nodeFlags: 33669121, rootNodeFlags: 33554433, nodeMatchedQueries: 0, flags: 0, nodes: [ Object({ nodeIndex: 0, parent: null, renderParent: null, bindingIndex: 0, outputIndex: 0, checkIndex: 0, flags: 33554433, childFlags: 114688, directChildFlags: 114688, childMatchedQueries: 0, matchedQueries: Object({ }), matchedQueryIds: 0, references: Object({ }), ngContentIndex: null, childCount: 1, bindings: [ ], bindingFlags: 0, outputs: [ ], element: Object({ ns: '', name: 'app-header', attrs: [ ], template: null, componentProvider: Object({ nodeIndex: 1, parent: , renderParent: , bindingIndex: 0, outputIndex: 0, checkIndex: 1, flags: 114688, childFlags: 0, directChildFlags: 0, childMatchedQueries: 0, matchedQueries: Object, matchedQueryIds: 0, references: Object, ngContentIndex: -1, childCount: 0, bindings: Array, bindingFlags: 0, outputs: Array ...
at
at NgcCookieConsentService.push../node_modules/ngx-cookieconsent/esm5/ngx-cookieconsent.es5.js.NgcCookieConsentService.init (http://localhost:9876/node_modules/ngx-cookieconsent/esm5/ngx-cookieconsent.es5.js?:149:1)
at new NgcCookieConsentService (http://localhost:9876/node_modules/ngx-cookieconsent/esm5/ngx-cookieconsent.es5.js?:96:1)

Desired functionality

The usecase is just load the service in the OnInit method and use it...

Mention any other details that might be useful

It does not slide underneath in mobile browser

Bug Report or Feature Request (mark with an x)

- [X ] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version: 3.1.1
- ngx-cookieconsent version: 2.2.3

OS Version?

Windows 10

Angular, Node and al Versions?

Angular CLI: 8.3.8
Node: 12.13.0
OS: win32 x64
Angular: 8.2.10
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package Version

@angular-devkit/architect 0.803.8
@angular-devkit/build-angular 0.803.8
@angular-devkit/build-optimizer 0.803.8
@angular-devkit/build-webpack 0.803.8
@angular-devkit/core 8.3.8
@angular-devkit/schematics 8.3.8
@angular/cdk 8.2.3
@angular/cli 8.3.8
@angular/material 8.2.3
@angular/material-moment-adapter 8.2.3
@ngtools/webpack 8.3.8
@schematics/angular 8.3.8
@schematics/update 0.803.8
rxjs 6.5.3
typescript 3.5.3
webpack 4.39.2

Repro steps

run the application in mobile

The log given by the failure

cookie

Desired functionality

the box should slide underneath

Mention any other details that might be useful

It does not always happen

Error: Cannot find name 'NgcInitializeEvent' and 'NgcStatusChangeEvent' AND Cannot read property 'initialise' of undefined

Hi,

I would like to use ngx-cookie consent package in my angular 4 application(built with angular cli) . I do not have a systemjs file. Hence except that part , I followed each step as in the documentation . I am having 4 error messages
two errors with following message

  1. Cannot read property 'initialise' of undefined
    at NgcCookieConsentService.init (cookieconsent.service.js:53)
    at new NgcCookieConsentService (cookieconsent.service.js:23)
    at _createClass (core.es5.js:9532)
    at createProviderInstance$1 (core.es5.js:9500)
    at resolveNgModuleDep (core.es5.js:9485)
    at NgModuleRef
    .get (core.es5.js:10577)
    at resolveDep (core.es5.js:11080)
    at createClass (core.es5.js:10933)
    at createDirectiveInstance (core.es5.js:10764)
    at createViewNodes (core.es5.js:12212)

  2. Cannot find name 'NgcInitializeEvent'.
    Cannot find name 'NgcStatusChangeEvent'.

Please help.

It's not possible to close completely the Cookie Policy once answered

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [ ] feature request

OS and Version?

Versions

Angular CLI: 6.0.0
Node: 10.0.0
OS: darwin x64
Angular: 6.0.0

Repro steps

The log given by the failure

Desired functionality

In this moment once you answer the consent, the popup closes but an small tab with the title "Cookie Policy" is left. I need to close everything once is answered but there isn't a close method.

Mention any other details that might be useful

Manage cookies of multiple domains in one application

Bug Report or Feature Request (mark with an x)

- [x ] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version: 3.1.0
- ngx-cookieconsent version: ^2.0.0

OS Version?

CentOS 7.6.1810

Angular, Node and al Versions?

Angular CLI: 7.0.5
Node: 9.11.1
OS: win32 x64
Angular: 7.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.10.5
@angular-devkit/build-angular 0.11.4
@angular-devkit/build-optimizer 0.11.4
@angular-devkit/build-webpack 0.11.4
@angular-devkit/core 7.0.5
@angular-devkit/schematics 7.0.5
@angular/cdk 7.0.4
@angular/cli 7.0.5
@angular/material 7.0.4
@angular/platform-server 7.0.4
@ngtools/webpack 7.1.4
@schematics/angular 7.0.5
@schematics/update 0.10.5
rxjs 6.3.3
typescript 3.1.6
webpack 4.23.1

Repro steps

NA

The log given by the failure

NA

Desired functionality

Be able to set the NgcCookieConsentConfig.cookieDomain property to multiple domains.
In my case, multiple domains are managed by the same angular application

Mention any other details that might be useful

Cookie revoke button not hideable

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

I've found out that when I set revokable: false to false and when I declined or accepted the police that the revoke button at the bottom left side is still there but I want to remove it completely when a decision was made. So something might be broken here?

CookieConsent and Library Versions?

- cookieconsent version: 3.1.1
- ngx-cookieconsent version: 2.2.3

OS Version?

macOS(Catalina)

Angular, Node and al Versions?

Angular CLI: 7.3.5
Node: 12.4.0
OS: darwin x64
Angular:
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.13.5
@angular-devkit/core         7.3.5
@angular-devkit/schematics   7.3.5
@schematics/angular          7.3.5
@schematics/update           0.13.5
rxjs                         6.3.3
typescript                   3.2.4

Repro steps

Setup the cookie consent with the following options and accept or decline the cookies:

const cookieConfig: NgcCookieConsentConfig = {
  cookie   : {
    domain: environment.cookieDomain
  },
  position : 'bottom-left',
  theme    : 'classic',
  palette  : {
    popup : {
      background: 'var(--secondary-color)',
      text      : '#ffffff',
      link      : '#ffffff'
    },
    button: {
      background: 'var(--main-color)',
      text      : '#ffffff',
      border    : 'transparent'
    }
  },
  revokable: false,
  type     : 'opt-in',
  content  : {
    message: 'Test',
    allow  : 'Accept',
    deny   : 'Decline',
    link   : 'Privacy',
    href   : '/privacy'
  }
};

The log given by the failure

There is no stacktrace or errors given.

Desired functionality

There should be no button at the left corner to open the cookie notice again.

accessibilty updates

Hello Guys,

I am using you package for an accessibility project. A colleague run accessibility tests and shared through this issue and change updates to be made to improve the pop up window.
I am trying to run ngx-cookieconsent to do a PR soon.

- [* ] feature request:
-> removing aria-label="cookieconsent" from the div (aria-labelledby is enough)
-> using real buttons instead of a a html tag with role set to button
-> No need of aria-label in these links because text links are understandables, but if you want to use aria-label translate them. let the user to input translate inside aria-label.
-> put the text of the popup and the links inside a tag ( p or div html tag)

Before starting any changes are you interesting by this feedback ?

CookieConsent and Library Versions?

- cookieconsent version: 3.1.0
- ngx-cookieconsent version: 2.0.0

B.R

.initialize$ is not fire up

i have checked your code and this problen still persist
The initialize$ stream is never called. I think this is coming from the init method in NgcCookieConsentService declaring this.config.onInitialize whereas the callback hook in cookieconsent.js is onInitialise (with an 's' not a 'z'). I fixed this locally and the callback seems to be working correctly now.

so please change that and release that in new release ASAP

in using "ngx-cookieconsent": "^2.2.2","cookieconsent": "^3.1.1",

Need simple config option to support cookieconsent location:true

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x ] feature request

CookieConsent and Library Versions?

- cookieconsent version: 3.1.1
- ngx-cookieconsent version: 2.2.2

OS Version?

MacOS Mojave

Angular, Node and al Versions?

Angular CLI: 6.2.3
Node: 11.14.0
Angular: 6.1.9

Repro steps

N/A

The log given by the failure

N/A

Desired functionality

https://cookieconsent.osano.com/documentation/javascript-api/ indicates that you can specify location:true in the configuration to easily enable the display of the popup only in countries that require it (and hide in others).

ngx-cookieconsent does not appear to support this, since the Typescript compiler requires an NgcLocationOptions object.

Is there an easy way to configure this? If not, would it be possible to add support for it?

Mention any other details that might be useful

Angular 6 support

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [* ] feature request

When use it with Angular 6, there're some error like.
node_modules/rxjs/Observable"' has no exported member 'Observable'.
node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.

Expected behavior:
Should be compatible with Angular 6

Stackblitz demo does not work

Bug Report or Feature Request (mark with an x)

- [x] bug report 
- [ ] feature request

In master branch (commit 43717bc):
https://stackblitz.com/github/tinesoft/ngx-cookieconsent/tree/master/demo
or
https://stackblitz.com/github/tinesoft/ngx-cookieconsent/tree/43717bc/demo

After opening, it asks to install missing packages (@nguniversal/commonngx-cookieconsent@angularclass/hmr). After installing, nothing happens, but there is an error in console:

ERROR TypeError: Cannot read property 'initialise' of undefined
    at NgcCookieConsentService.init (cookieconsent.service.ts:162)
    at new NgcCookieConsentService (cookieconsent.service.ts:119)
    at _createClass (ng_module.ts:176)
    at _createProviderInstance (ng_module.ts:144)
    at resolveNgModuleDep (ng_module.ts:106)
    at NgModuleRef_.get (refs.ts:507)
    at resolveDep (provider.ts:423)
    at createClass (provider.ts:283)
    at createDirectiveInstance (provider.ts:136)
    at createViewNodes (view.ts:303)

Readme Instruction for Modifying Text/Links Outdated

Bug Report or Feature Request (mark with an x)

- [x ] bug report -> please search issues before submitting

Related issue: Is it possible to include multiple links and insert them in the middle of a sentence?

CookieConsent and Library Versions?

- ngx-cookieconsent version:2.2.0

Repro steps

Use code example from the readme.

The log given by the failure

ERROR in src/app/app.module.ts(66,5): error TS2322: Type '{ message: string; privacyPolicyLink: string; privacyPolicyHref: string; tosLink: string; tosHref: string; }' is not assignable to type 'NgcContentOptions'.
  Object literal may only specify known properties, and 'privacyPolicyLink' does not exist in type 'NgcContentOptions'.

Desired functionality

Readme example compatible with types.

Mention any other details that might be useful

E.g. Readme.md messageLink (camel case) in the types: messagelink (lower case)
html-elements.ts

Also content options does not have any of these props:

    cookiePolicyLink: 'Cookie Policy',
    cookiePolicyHref: 'https://cookie.com',

    privacyPolicyLink: 'Privacy Policy',
    privacyPolicyHref: 'https://privacy.com',

    tosLink: 'Terms of Service',
    tosHref: 'https://tos.com',

content-options.ts

How to dynamic set domain to current one

Hello, I'm trying to set the domain property to using the current origin domain in app.module.
How can I do it?
I have this definition in imports and when try to set the domain using function or expression the compiler throw exception that is not possible. If I using window.local.domain the SSR throw exception that can't resolve window object. Is it possible to pass some provider which will set the domain?

NgcCookieConsentModule.forRoot(
{
'cookie': {
'domain': getCurrentDomain()
},
'palette': {
'popup': {
'background': '#efefef',
'text': '#404040'
},
'button': {
'background': '#8ec760',
'text': '#ffffff'
}
},
'theme': 'classic',
'position': 'bottom-right'
}),

Incompatible with angular 10

Bug Report or Feature Request (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request

CookieConsent and Library Versions?

- cookieconsent version: 3.1.0
- ngx-cookieconsent version: master

OS Version?

Angular, Node and al Versions?

Angular 10

Repro steps

  • ng add ngx-cookieconsent
  • add a component with ngx-cookieconsent
  • ng build --prod

The log given by the failure

error TS2307: Cannot find module 'ngx-cookieconsent' or its corresponding type declarations.
 11 import { NgcCookieConsentService } from 'ngx-cookieconsent';

Desired functionality

Should compile without error

Mention any other details that might be useful

I already fixed another bug related to angular 10 here #86 . As the Project is not using angular-cli I didn't open a PR to update it as I don't have time to investigate what should be changed etc.

I would recommend investigating if a switch to angular-cli can be made for the long run.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.