src/app/services/storage.service.ts
Properties |
Methods |
constructor()
|
Defined in src/app/services/storage.service.ts:7
|
delete | ||||||
delete(key: string)
|
||||||
Defined in src/app/services/storage.service.ts:28
|
||||||
Parameters :
Returns :
void
|
deleteAll |
deleteAll()
|
Defined in src/app/services/storage.service.ts:25
|
Returns :
void
|
get | ||||||
get(key: string)
|
||||||
Defined in src/app/services/storage.service.ts:11
|
||||||
Parameters :
Returns :
string
|
getObject | ||||||
getObject(key: string)
|
||||||
Defined in src/app/services/storage.service.ts:15
|
||||||
Parameters :
Returns :
any
|
set |
set(key: string, value: any)
|
Defined in src/app/services/storage.service.ts:21
|
Returns :
void
|
storage |
storage:
|
Type : Storage
|
Defined in src/app/services/storage.service.ts:7
|
import { Injectable } from '@angular/core';
declare var window: any;
@Injectable()
export class StorageService {
storage: Storage;
constructor() {
this.storage = window.sessionStorage;
}
get(key: string): string {
return this.storage.getItem(key);
}
getObject(key: string): any {
const value = this.storage.getItem(key);
const obj = value && value.length > 0 ? JSON.parse(value) : null;
return obj;
}
set(key: string, value: any): void {
value = typeof value === 'string' ? value : JSON.stringify(value);
return this.storage.setItem(key, value);
}
deleteAll(): void {
this.storage.clear();
}
delete(key: string): void {
this.storage.removeItem(key);
}
}