I have moved my application from Angular 6 to Angular Universal and since doing this I have noticed this error in the console:
sessionStorage is not defined
It is moaning about this service:
export class SessionService {
constructor(
private key: string
) {
}
save(json: any) {
sessionStorage.setItem(this.key, JSON.stringify(json));
}
get() {
return JSON.parse(sessionStorage.getItem(this.key));
}
clear() {
sessionStorage.clear();
}
}
I have seen that you can do something like:
if (!isPlatformBrowser(this.platformId)) return;
but this service is actually extended like this:
import { Injectable } from '@angular/core';
import { SessionService } from './session.service';
@Injectable({
providedIn: 'root'
})
export class QuestionSessionService extends SessionService {
constructor() {
super(
'questions'
);
}
}
So I can't add @Inject(PLATFORM_ID) private platformId: Object
to the constructor.
Can someone help me out with this issue?