Angular Signal Generators
    Preparing search index...
    • Creates a signal that will sync changes to some sort of storage. The next time a signal with the same key is read, an alternative value to the initial value will be used. It's probably better to use sessionStorageSignal or localStorageSignal instead of this.

      Type Parameters

      • T

        The type of the value that should be stored and deserialized.

      Parameters

      • initialValue: T

        The initialValue for the signal if it isn't in storage.

      • key: string

        The key to use for storage. This should be unique to avoid conflicts when deserializing values.

      • storageProvider: StorageSignalStore<T>

        The provider of storage.

      • options: CreateSignalOptions<T> = {}

        Standard create signal options.

      Returns WritableSignal<T>

      A writable signal

      const storageProvider = Map<string, number>();
      const signal1 = storageSignal(1, 'someKey', storageProvider);
      signal1.set(100);
      const signal2 = storageSignal(1, 'someKey', storageProvider);
      console.log(signal1(), signal2()); // [LOG]: 100, 100