W3cubDocs

/Angular

ToSignalOptions

interface

Options for toSignal.

interface ToSignalOptions<T> {
  initialValue?: T
  requireSync?: boolean
  injector?: Injector
  manualCleanup?: boolean
}

Properties

Property Description
initialValue?: T

Initial value for the signal produced by toSignal.

This will be the value of the signal until the observable emits its first value.

requireSync?: boolean

Whether to require that the observable emits synchronously when toSignal subscribes.

If this is true, toSignal will assert that the observable produces a value immediately upon subscription. Setting this option removes the need to either deal with undefined in the signal type or provide an initialValue, at the cost of a runtime error if this requirement is not met.

injector?: Injector

Injector which will provide the DestroyRef used to clean up the Observable subscription.

If this is not provided, a DestroyRef will be retrieved from the current injection context, unless manual cleanup is requested.

manualCleanup?: boolean

Whether the subscription should be automatically cleaned up (via DestroyRef) when toObservable's creation context is destroyed.

If manual cleanup is enabled, then DestroyRef is not used, and the subscription will persist until the Observable itself completes.

© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/core/rxjs-interop/ToSignalOptions