35 lines
738 B
TypeScript
35 lines
738 B
TypeScript
// #docregion
|
|
import { Inject, Injectable, InjectionToken } from '@angular/core';
|
|
|
|
// #docregion storage-token
|
|
export const BROWSER_STORAGE = new InjectionToken<Storage>('Browser Storage', {
|
|
providedIn: 'root',
|
|
factory: () => localStorage
|
|
});
|
|
// #enddocregion storage-token
|
|
|
|
// #docregion inject-storage-token
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class BrowserStorageService {
|
|
constructor(@Inject(BROWSER_STORAGE) public storage: Storage) {}
|
|
|
|
get(key: string) {
|
|
this.storage.getItem(key);
|
|
}
|
|
|
|
set(key: string, value: string) {
|
|
this.storage.setItem(key, value);
|
|
}
|
|
|
|
remove(key: string) {
|
|
this.storage.removeItem(key);
|
|
}
|
|
|
|
clear() {
|
|
this.storage.clear();
|
|
}
|
|
}
|
|
// #enddocregion inject-storage-token
|