Code Monkey home page Code Monkey logo

Comments (4)

Kenji94 avatar Kenji94 commented on June 12, 2024 1

It happens very rarely that's why it is difficult to find the origin of the problem.
Whenever the user change the website language, I call "updateCookiePopupLanguage()" to modify the popup if it is visible.

private updateCookiePopupLanguage() {

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'];
    try {
      this.ccService.destroy(); // remove previous cookie bar (with default messages)
    } catch (e) {
      this.consoleLoggerService.error('updateCookiePopupLanguage, this.ccService.destroy() crashed', e);
    }

      const cookieStatus = localStorage.getItem(Constants.cookieStatus);
      this.consoleLoggerService.log('cookieStatus', cookieStatus);
      if (cookieStatus && (cookieStatus === 'allow' || cookieStatus === 'dismiss')) {
        this.consoleLoggerService.log('do not show again the cookie popup');
        return;
      }
      this.ccService.init(this.ccService.getConfig()); // show popup
 
  });

}

from ngx-cookieconsent.

tinesoft avatar tinesoft commented on June 12, 2024

Hi @Kenji94 ,

I've just tested with your config on latest version of Angular (v9.1.0) and never encountered this error... I'm afraid there is not much i can do at this point...

Why do you need to call this.ccService.destroy()? and where do you call it?

from ngx-cookieconsent.

jaco-terbraak avatar jaco-terbraak commented on June 12, 2024

I also regularly encounter this error in my Angular 9 application. It happens occasionally when ccService.destroy() is called.
I need to call this method when I load the consent from a different source, and need to hide the CC bar.

I suspect it happens because the destroy() call tries to access the options object, which might not yet have been initialized in the view. A null check would probably fix it.

from ngx-cookieconsent.

jaco-terbraak avatar jaco-terbraak commented on June 12, 2024

Some further investigation tells me that the https://github.com/osano/cookieconsent dependency might be the problem.

from ngx-cookieconsent.

Related Issues (20)

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.