Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with universal (angular 6+) #18

Open
alo opened this issue Jul 9, 2018 · 11 comments
Open

Not working with universal (angular 6+) #18

alo opened this issue Jul 9, 2018 · 11 comments

Comments

@alo
Copy link

alo commented Jul 9, 2018

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)

@tinesoft
Copy link
Owner

Hi @alo

Thanks for creating the issue. However can you elaborate on the exact problem your are facing with this library and universal? i mean: what command did you run? what is the stacktrace? any other repro steps will be useful....

tinesoft added a commit that referenced this issue Jul 18, 2018
- update demo application and add SSR support

BREAKING CHANGE:

The mininmum version of Angular is now v6+ and of Node is v8+

Closes #17 and #18
tinesoft added a commit that referenced this issue Jul 18, 2018
- update demo application and add SSR support

BREAKING CHANGE:

- Minimum version of Angular is now v6+
- Minimum version of Node is v8+

Closes #17 and #18
@zackarychapple
Copy link

@alo, I was running into the same issue. I followed the instructions on adding everything to the module, but also had to add the injector to the root app.component

@alo
Copy link
Author

alo commented Aug 22, 2018

Thanks @zackarychapple. That's it. Even if you don't use it, you have to add the injector to the root app.component

@tinesoft is it enough information for you or can I help you with something?

@neilime
Copy link

neilime commented Nov 20, 2018

Here is my workaround :

import { Component, Injector, Inject, PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';
import { NgcCookieConsentService } from 'ngx-cookieconsent';

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

  constructor(    
	@Inject(PLATFORM_ID) private readonly platformId: Object,
    private readonly injector: Injector
  ) {}

  ngOnInit() {
    super.ngOnInit();
    if (!isPlatformBrowser(this.platformId)) {
      return;
    }

    const ccService = this.injector.get(NgcCookieConsentService);
	
    // Configure stuff
    // ...
    ccService.init(ccService.getConfig()); 
  }
}

@Luarb
Copy link

Luarb commented Jan 9, 2019

ccService.init(ccService.getConfig());

If you Import NgcCookieConsentService as you did, it will trigger this error :

Node Express server listening on http://localhost:4000
ERROR { Error: StaticInjectorError(AppServerModule)[NgcCookieConsentService]:
  StaticInjectorError(Platform: core)[NgcCookieConsentService]:
    NullInjectorError: No provider for NgcCookieConsentService!

but if you do create an Injectable :

import { Injectable, Injector, PLATFORM_ID, Inject } from '@angular/core';
import { NgcCookieConsentService } from 'ngx-cookieconsent';
import { isPlatformServer } from '@angular/common';

@Injectable()
export class CookieLaw {
    constructor(
        private readonly injector: Injector,
        @Inject(PLATFORM_ID) private platformId

    ) {
        if (!isPlatformServer(this.platformId)) {
             this.injector.get(NgcCookieConsentService);
        }
    }

}

and then simply import it in your app.component (also put it as a parameter on the constructor) & app.module . This worked for me.

Edit* :
I forgot to mention, you should import the NgcCookieConsentModule on app.browser.module.

@asahajit
Copy link

asahajit commented Oct 2, 2019

Followed the instruction as documented in Angular 8. But the popup is not cumming in page.
image

@nilot111
Copy link

I I have same issue, but i could not been able to solve it. I am running angular universal 10 with following command:
npm run build:ssr && npm run serve:ssr
Which represents:
"serve:ssr": "node dist/compy/server/main.js",
"build:ssr": "ng build --prod && ng run compy:server:production",

And i am getting following error:
ERROR TypeError: Cannot read property 'initialise' of undefined
at ngx_cookieconsent_NgcCookieConsentService.init (C:\Coding\compyFront\dist\compy\server\main.js:1:1693848)
at new ngx_cookieconsent_NgcCookieConsentService (C:\Coding\compyFront\dist\compy\server\main.js:1:1693078)
at Object.NgcCookieConsentService_Factory [as factory] (C:\Coding\compyFront\dist\compy\server\main.js:1:1695042)
at R3Injector.hydrate (C:\Coding\compyFront\dist\compy\server\main.js:1:2806442)
at R3Injector.get (C:\Coding\compyFront\dist\compy\server\main.js:1:2803174)
at NgModuleRef$1.get (C:\Coding\compyFront\dist\compy\server\main.js:1:2981584)
at Object.get (C:\Coding\compyFront\dist\compy\server\main.js:1:2950678)
at getOrCreateInjectable (C:\Coding\compyFront\dist\compy\server\main.js:1:2717832)
at Module.ɵɵdirectiveInject (C:\Coding\compyFront\dist\compy\server\main.js:1:2837088)
at NodeInjectorFactory.AppComponent_Factory [as factory] (C:\Coding\compyFront\dist\compy\server\main.js:1:1699228)

Please your help, since i am following everything you mention in documentation. Thanks in advance.

@ilovethedrama
Copy link

I I have same issue, but i could not been able to solve it. I am running angular universal 10 with following command:
npm run build:ssr && npm run serve:ssr
Which represents:
"serve:ssr": "node dist/compy/server/main.js",
"build:ssr": "ng build --prod && ng run compy:server:production",

And i am getting following error:
ERROR TypeError: Cannot read property 'initialise' of undefined
at ngx_cookieconsent_NgcCookieConsentService.init (C:\Coding\compyFront\dist\compy\server\main.js:1:1693848)
at new ngx_cookieconsent_NgcCookieConsentService (C:\Coding\compyFront\dist\compy\server\main.js:1:1693078)
at Object.NgcCookieConsentService_Factory [as factory] (C:\Coding\compyFront\dist\compy\server\main.js:1:1695042)
at R3Injector.hydrate (C:\Coding\compyFront\dist\compy\server\main.js:1:2806442)
at R3Injector.get (C:\Coding\compyFront\dist\compy\server\main.js:1:2803174)
at NgModuleRef$1.get (C:\Coding\compyFront\dist\compy\server\main.js:1:2981584)
at Object.get (C:\Coding\compyFront\dist\compy\server\main.js:1:2950678)
at getOrCreateInjectable (C:\Coding\compyFront\dist\compy\server\main.js:1:2717832)
at Module.ɵɵdirectiveInject (C:\Coding\compyFront\dist\compy\server\main.js:1:2837088)
at NodeInjectorFactory.AppComponent_Factory [as factory] (C:\Coding\compyFront\dist\compy\server\main.js:1:1699228)

Please your help, since i am following everything you mention in documentation. Thanks in advance.

did you manage to fix this error in the end? I'm running into the same error

@casper5822
Copy link

casper5822 commented Nov 25, 2020

Hello,
My error is not on initialise.
My problem is that with a custom layout the click to open the popup that doesn't expand the popup.
In my case i have angular 8 + angular universal + domino.

Do you have this problem?

@TGihan
Copy link

TGihan commented Dec 13, 2020

Hi,
I am also getting the same error when execute npm run server with angular universal

Node Express server listening on http://localhost:4000 ERROR TypeError: Cannot read property 'initialise' of undefined

"ngx-cookieconsent": "^2.2.3",
Angular 9

@rmartin-sommset
Copy link

Hi TGihan, were you able to resolve this initialise issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

12 participants