fix: Updated localStorage access to check for window object existence to avoid SSR issues.
This commit is contained in:
@@ -65,7 +65,7 @@ export class BaseTableComponent<TModel, TApiService extends ApiService<TModel>>
|
||||
}
|
||||
};
|
||||
|
||||
theme: GuiTheme = localStorage.getItem('theme') === 'dark' ? GuiTheme.DARK : GuiTheme.FABRIC;
|
||||
theme: GuiTheme = typeof window !== 'undefined' ? (localStorage.getItem('theme') === 'dark' ? GuiTheme.DARK : GuiTheme.FABRIC) : GuiTheme.DARK;
|
||||
|
||||
private themeSubscription: Subscription = new Subscription();
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ export class LoginComponent {
|
||||
IsPwdHidden: boolean = true;
|
||||
|
||||
constructor(private authService: AuthenticationService, @Inject(MAT_DIALOG_DATA) public data: any) {
|
||||
//localStorage.getItem('theme') === 'dark'
|
||||
if (typeof (this.afterLogin) == typeof (data.afterLogin))
|
||||
this.afterLogin = data.afterLogin;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export class NavMenuComponent {
|
||||
}
|
||||
|
||||
get isDarkTheme(): boolean {
|
||||
return localStorage.getItem('theme') === 'dark'
|
||||
return (typeof window !== 'undefined')?(localStorage.getItem('theme') === 'dark'):true;
|
||||
}
|
||||
|
||||
collapse() {
|
||||
|
||||
@@ -17,7 +17,8 @@ export class ColorModeService {
|
||||
}
|
||||
|
||||
setTheme(theme: Theme) {
|
||||
localStorage.setItem('theme', theme)
|
||||
if (typeof window !== 'undefined')
|
||||
localStorage.setItem('theme', theme)
|
||||
this.updateTheme();
|
||||
}
|
||||
|
||||
@@ -76,7 +77,7 @@ export const ParseTheme: (value: string) => Theme | undefined = (value: string)
|
||||
}
|
||||
|
||||
export function GetLocalTheme(): Theme {
|
||||
let sTheme: string | null = localStorage.getItem('theme');
|
||||
let sTheme: string | null = (typeof window !== 'undefined') ? (localStorage.getItem('theme')) : 'dark';
|
||||
|
||||
if (sTheme === null)
|
||||
return Theme.Dark;
|
||||
|
||||
Reference in New Issue
Block a user