|
|
|
@ -1,44 +1,43 @@ |
|
|
|
import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; |
|
|
|
import { inject, Injectable, PLATFORM_ID } from '@angular/core'; |
|
|
|
import { isPlatformBrowser } from '@angular/common'; |
|
|
|
|
|
|
|
@Injectable({ |
|
|
|
providedIn: 'root', |
|
|
|
}) |
|
|
|
export class AbpLocalStorageService implements Storage { |
|
|
|
private isBrowser: boolean; |
|
|
|
private platformId = inject(PLATFORM_ID); |
|
|
|
|
|
|
|
constructor(@Inject(PLATFORM_ID) private platformId: unknown) { |
|
|
|
this.isBrowser = isPlatformBrowser(this.platformId); |
|
|
|
constructor() { |
|
|
|
} |
|
|
|
[name: string]: any; |
|
|
|
get length(): number { |
|
|
|
return this.isBrowser ? localStorage.length : 0; |
|
|
|
return isPlatformBrowser(this.platformId) ? localStorage.length : 0; |
|
|
|
} |
|
|
|
|
|
|
|
clear(): void { |
|
|
|
if (this.isBrowser) { |
|
|
|
if (isPlatformBrowser(this.platformId)) { |
|
|
|
localStorage.clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
getItem(key: string): string | null { |
|
|
|
if (!this.isBrowser) { |
|
|
|
if (!isPlatformBrowser(this.platformId)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
return localStorage.getItem(key); |
|
|
|
} |
|
|
|
key(index: number): string | null { |
|
|
|
if (!this.isBrowser) { |
|
|
|
if (!isPlatformBrowser(this.platformId)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
return localStorage.key(index); |
|
|
|
} |
|
|
|
removeItem(key: string): void { |
|
|
|
if (this.isBrowser) { |
|
|
|
if (isPlatformBrowser(this.platformId)) { |
|
|
|
localStorage.removeItem(key); |
|
|
|
} |
|
|
|
} |
|
|
|
setItem(key: string, value: string): void { |
|
|
|
if (this.isBrowser) { |
|
|
|
if (isPlatformBrowser(this.platformId)) { |
|
|
|
localStorage.setItem(key, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|