File

src/services/LocalStorage.ts

Methods

getItem
getItem(key: string, defaultValue: any)
Returns : any
setItem
setItem(key: string, value: any)
Returns : void
removeItem
removeItem(key: string)
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);
    }

}

results matching ""

    No results matching ""