tinesoft / ngx-cookieconsent

Cookie :cookie: Consent module for Angular.
https://tinesoft.github.io/ngx-cookieconsent/
MIT License
163 stars 35 forks source link

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

Open nktkarnany opened 6 years ago

nktkarnany commented 6 years ago

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

tinesoft commented 6 years ago

Hi @nktkarnany

Thanks for reporting this. I will update the README.md section about i18n to mention your hack, which is, to me, the best way to address the issue (due to async nature of translation mechanism).