mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2026-04-27 15:50:11 +00:00
BETTERZON-37: Adding cookie notice popup (#23)
This commit is contained in:
@@ -1,10 +1,69 @@
|
||||
import { Component } from '@angular/core';
|
||||
import {Component, OnDestroy, OnInit} from '@angular/core';
|
||||
import {NgcCookieConsentService, NgcInitializeEvent, NgcNoCookieLawEvent, NgcStatusChangeEvent} from 'ngx-cookieconsent';
|
||||
import {Subscription} from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
templateUrl: './app.component.html',
|
||||
styleUrls: ['./app.component.css']
|
||||
selector: 'app-root',
|
||||
templateUrl: './app.component.html',
|
||||
styleUrls: ['./app.component.css']
|
||||
})
|
||||
export class AppComponent {
|
||||
title = 'Betterzon';
|
||||
export class AppComponent implements OnInit, OnDestroy {
|
||||
title = 'Betterzon';
|
||||
|
||||
// Cookie popup stuff
|
||||
// Docs on https://www.npmjs.com/package/ngx-cookieconsent
|
||||
private popupOpenSubscription: Subscription;
|
||||
private popupCloseSubscription: Subscription;
|
||||
private initializeSubscription: Subscription;
|
||||
private statusChangeSubscription: Subscription;
|
||||
private revokeChoiceSubscription: Subscription;
|
||||
private noCookieLawSubscription: Subscription;
|
||||
|
||||
constructor(
|
||||
private ccService: NgcCookieConsentService
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
// subscribe to cookieconsent observables to react to main events
|
||||
this.popupOpenSubscription = this.ccService.popupOpen$.subscribe(
|
||||
() => {
|
||||
// you can use this.ccService.getConfig() to do stuff...
|
||||
});
|
||||
|
||||
this.popupCloseSubscription = this.ccService.popupClose$.subscribe(
|
||||
() => {
|
||||
// you can use this.ccService.getConfig() to do stuff...
|
||||
});
|
||||
|
||||
this.initializeSubscription = this.ccService.initialize$.subscribe(
|
||||
(event: NgcInitializeEvent) => {
|
||||
// you can use this.ccService.getConfig() to do stuff...
|
||||
});
|
||||
|
||||
this.statusChangeSubscription = this.ccService.statusChange$.subscribe(
|
||||
(event: NgcStatusChangeEvent) => {
|
||||
// you can use this.ccService.getConfig() to do stuff...
|
||||
});
|
||||
|
||||
this.revokeChoiceSubscription = this.ccService.revokeChoice$.subscribe(
|
||||
() => {
|
||||
// you can use this.ccService.getConfig() to do stuff...
|
||||
});
|
||||
|
||||
this.noCookieLawSubscription = this.ccService.noCookieLaw$.subscribe(
|
||||
(event: NgcNoCookieLawEvent) => {
|
||||
// you can use this.ccService.getConfig() to do stuff...
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
// unsubscribe to cookieconsent observables to prevent memory leaks
|
||||
this.popupOpenSubscription.unsubscribe();
|
||||
this.popupCloseSubscription.unsubscribe();
|
||||
this.initializeSubscription.unsubscribe();
|
||||
this.statusChangeSubscription.unsubscribe();
|
||||
this.revokeChoiceSubscription.unsubscribe();
|
||||
this.noCookieLawSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user