@theredhead — Frontend Library - v1.0.0
    Preparing search index...

    Angular service for persisting key-value data.

    Delegates to the IStorageStrategy provided via STORAGE_STRATEGY. Defaults to LocalStorageStrategy (i.e. localStorage).

    Inject this service instead of calling localStorage directly so that storage behaviour can be swapped application-wide through DI.

    export class MyComponent {
    private readonly storage = inject(StorageService);

    public save(key: string, data: unknown): void {
    this.storage.setItem(key, JSON.stringify(data));
    }

    public load(key: string): unknown | null {
    const raw = this.storage.getItem(key);
    return raw ? JSON.parse(raw) : null;
    }
    }
    Index

    Constructors

    Methods

    • Retrieve a value by key. Returns null when the key does not exist.

      Parameters

      • key: string

      Returns string | null

    • Remove the value for the given key.

      Parameters

      • key: string

      Returns void

    • Store a value under the given key.

      Parameters

      • key: string
      • value: string

      Returns void