Skip to content

Commit c6ef246

Browse files
committed
119602: Fix SSR error by making klaroService optional
KlaroService handles cookies which are not applicable during SSR. By making the service optional, and handling the case when it is not available, SSR can do its work without throwing NullInjectorErrors.
1 parent b44f74a commit c6ef246

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/app/info/accessibility-settings/accessibility-settings.component.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnDestroy, OnInit } from '@angular/core';
1+
import { Component, OnDestroy, OnInit, Optional } from '@angular/core';
22
import { AuthService } from '../../core/auth/auth.service';
33
import {
44
AccessibilitySetting,
@@ -8,7 +8,7 @@ import {
88
import { BehaviorSubject, distinctUntilChanged, map, Subscription, take } from 'rxjs';
99
import { NotificationsService } from '../../shared/notifications/notifications.service';
1010
import { TranslateService } from '@ngx-translate/core';
11-
import { isEmpty } from 'src/app/shared/empty.util';
11+
import { hasValue, isEmpty } from 'src/app/shared/empty.util';
1212
import { AlertType } from '../../shared/alert/alert-type';
1313
import { KlaroService } from '../../shared/cookies/klaro.service';
1414

@@ -35,7 +35,7 @@ export class AccessibilitySettingsComponent implements OnInit, OnDestroy {
3535
protected settingsService: AccessibilitySettingsService,
3636
protected notificationsService: NotificationsService,
3737
protected translateService: TranslateService,
38-
protected klaroService: KlaroService,
38+
@Optional() protected klaroService: KlaroService,
3939
) {
4040
}
4141

@@ -45,11 +45,19 @@ export class AccessibilitySettingsComponent implements OnInit, OnDestroy {
4545
this.subscriptions.push(
4646
this.authService.isAuthenticated().pipe(distinctUntilChanged())
4747
.subscribe(val => this.isAuthenticated.next(val)),
48-
this.klaroService.getSavedPreferences().pipe(
49-
map(preferences => preferences?.accessibility === true),
50-
distinctUntilChanged(),
51-
).subscribe(val => this.cookieIsAccepted.next(val)),
5248
);
49+
50+
if (hasValue(this.klaroService)) {
51+
this.subscriptions.push(
52+
this.klaroService.getSavedPreferences().pipe(
53+
map(preferences => preferences?.accessibility === true),
54+
distinctUntilChanged(),
55+
).subscribe(val => this.cookieIsAccepted.next(val))
56+
);
57+
} else {
58+
this.cookieIsAccepted.next(false);
59+
}
60+
5361
}
5462

5563
ngOnDestroy() {

0 commit comments

Comments
 (0)