Comments (11)
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());
}
}
from ngx-cookieconsent.
@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
from ngx-cookieconsent.
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?
from ngx-cookieconsent.
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....
from ngx-cookieconsent.
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.
from ngx-cookieconsent.
Followed the instruction as documented in Angular 8. But the popup is not cumming in page.
from ngx-cookieconsent.
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.
from ngx-cookieconsent.
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
from ngx-cookieconsent.
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?
from ngx-cookieconsent.
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
from ngx-cookieconsent.
Hi TGihan, were you able to resolve this initialise
issue?
from ngx-cookieconsent.
Related Issues (20)
- [Bug] HOT 2
- [Bug] Angular 13 not supported HOT 1
- [Bug] SSR - Cookie popup has not yet been instantiated. Cannot invoke {{methodName}}
- [Bug] ccService.initializing, ccService.initialized and ccService.initializationError does not exist on NgcCookieConsentService HOT 2
- [Feature] Angular 14 HOT 22
- The automated release is failing 🚨
- [Bug] Wrong `peerDependencies` for rxjs for Angular v14+ HOT 3
- Does not save its own cookie on AWS amplify HOT 1
- Cookie popup not appearing in published website HOT 1
- [Bug] Restrictive `peerDependency` of `rxjs` causes conflicts with other packages
- [Bug] whitelistPage and blacklistPage options are not working well
- [Bug] Support for Angular 15 HOT 1
- The automated release is failing 🚨
- [Bug] Needs to be Ivy compliant [Angular 16] HOT 18
- How do I opt-in a session when cookie consent is not required?
- Cookie-banner disabled by AdBlocker[Bug] HOT 1
- [chore] Update to latest Nx version
- [chore] Setup Nx Dependency Check ESLint
- [Feature] Add mobileForceFloat option HOT 1
- How to set consent? How to prevent popup opening after setting cookie? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ngx-cookieconsent.