src/services/LocalStorage.ts
getItem |
getItem(key: string, defaultValue: any)
|
Defined in src/services/LocalStorage.ts:6
|
Returns :
any
|
setItem |
setItem(key: string, value: any)
|
Defined in src/services/LocalStorage.ts:14
|
Returns :
void
|
removeItem |
removeItem(key: string)
|
Defined in src/services/LocalStorage.ts:18
|
Returns :
void
|
import {Injectable} from '@angular/core';
@Injectable()
export class LocalStorage {
getItem(key: string, defaultValue?: any): any {
if (localStorage.getItem(key)) {
return JSON.parse(localStorage.getItem(key));
} else {
return defaultValue;
}
}
setItem(key: string, value: any): void {
localStorage.setItem(key, JSON.stringify(value));
}
removeItem(key: string): void {
localStorage.removeItem(key);
}
}