File

src/app/services/consent.service.ts

Index

Properties
Methods

Constructor

constructor()

Methods

setConsent
setConsent(value: Consent)
Parameters :
Name Type Optional
value Consent No
Returns : void
unsetConsent
unsetConsent()
Returns : void

Properties

consent
Type : Consent
Default value : 'not-set'
Readonly consentChange
Default value : new ReplaySubject<Consent>(1)
import { Injectable, OnDestroy } from '@angular/core';
import { ReplaySubject } from 'rxjs';

export type Consent = 'not-set' | 'given' | 'rescinded';

@Injectable()
export class ConsentService implements OnDestroy {
  consent: Consent = 'not-set';

  readonly consentChange = new ReplaySubject<Consent>(1);

  constructor() {
    this.consentChange.next(this.consent);
  }

  ngOnDestroy(): void {
    this.consentChange.complete();
  }

  setConsent(value: Consent): void {
    if (this.consent !== value) {
      this.consent = value;
      this.consentChange.next(value);
    }
  }

  unsetConsent(): void {
    this.setConsent('not-set');
  }
}

results matching ""

    No results matching ""