src/services/storage.service.ts
Wrapper service for crud operations on the local Storage
clear |
clear()
|
Defined in src/services/storage.service.ts:16
|
Clears the whole localStorage for the application
Returns :
void
|
getItem |
getItem(key: void)
|
Defined in src/services/storage.service.ts:25
|
Gets an item with the given key from the localStorage
Parameters :
Returns :
string
|
key |
key(index: void)
|
Defined in src/services/storage.service.ts:34
|
Gets the literal key on the given index in the localStorage
Parameters :
Returns :
string
|
removeItem |
removeItem(key: void)
|
Defined in src/services/storage.service.ts:42
|
Removes an item with the given key from the localStorage
Parameters :
Returns :
void
|
setItem |
setItem(key: void, value: void)
|
Defined in src/services/storage.service.ts:51
|
Sets an item for the given key in the localStorage
Parameters :
Returns :
void
|
import {Injectable} from "@angular/core";
/**
* Wrapper service for crud operations on the local Storage
*/
@Injectable()
export class StorageService {
/**
* Clears the whole localStorage for the application
*/
clear(): void {
localStorage.clear();
}
/**
* Gets an item with the given key from the localStorage
* @param key The key to get the value from the localStorage
* @return {any} The value for the given key if exists, otherwise null
*/
getItem(key: string): string {
return localStorage.getItem(key);
}
/**
* Gets the literal key on the given index in the localStorage
* @param index The index in the localStorage to retrieve the literal key for
* @return {string} The literal key for the given index
*/
key(index: number): string {
return localStorage.key(index);
}
/**
* Removes an item with the given key from the localStorage
* @param key The key of the item to remove
*/
removeItem(key: string): void {
localStorage.removeItem(key);
}
/**
* Sets an item for the given key in the localStorage
* @param key The key of the item to set
* @param value The value of the item to in the localStorage
*/
setItem(key: string, value: string): void {
localStorage.setItem(key, value);
}
}