I'm the author of ngx-cookieconsent.
I have already answered the issues on the project's issues tracker, but for future googlers, here they are:
- 'NgcInitializeEvent' and 'NgcStatusChangeEvent' not found
You need to import them, if you want to use these events in your code:
import { NgcInitializeEvent, NgcStatusChangeEvent } from 'ngx-cookieconsent';
- Cookie status not persisted
your need to set 'cookie.domain'
parameter of configuration object (even in localhost), for cookies to be set properly:
import {NgcCookieConsentModule, NgcCookieConsentConfig} from 'ngx-cookieconsent';
const cookieConfig:NgcCookieConsentConfig = {
cookie: {
domain: 'localhost' // or 'your.domain.com' // it is mandatory to set a domain (even in localhost), for cookies to work properly
}
};
@NgModule({
declarations: [AppComponent, ...],
imports: [NgcCookieConsentModule.forRoot(cookieConfig), ...],
bootstrap: [AppComponent]
})
export class AppModule {
}
Note: if you are using Angular CLI for your consuming app, you can take advantage of environments to control the domain based on your running environment:
environments/environment.ts: (dev)
export const environment = {
production: false,
cookieDomain: 'localhost' // -<< must be 'localhost'
};
environments/environment.prod.ts: (prod)
export const environment = {
production: true,
cookieDomain: 'your.domain.com' // -<< must be the domain of deployed app
};
and use it as such:
import {NgcCookieConsentModule, NgcCookieConsentConfig} from 'ngx-cookieconsent';
import { environment } from './../environments/environment';
const cookieConfig:NgcCookieConsentConfig = {
cookie: {
domain: environment.cookieDomain // -<< domain will change base on your running env
}
};
@NgModule({
declarations: [AppComponent, ...],
imports: [NgcCookieConsentModule.forRoot(cookieConfig), ...],
bootstrap: [AppComponent]
})
export class AppModule {
}