Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

toSignal

      
      toSignal<T>()
    
Parameters

There are no parameters.

Overloads

      
      toSignal(source: Observable<T> | Subscribable<T>): Signal<T | undefined>
    
Parameters
source Observable<T> | Subscribable<T>
Returns

Signal<T | undefined>

      
      toSignal(source: Observable<T> | Subscribable<T>, options: ToSignalOptions & { initialValue?: undefined; requireSync?: false; }): Signal<T | undefined>
    
Parameters
source Observable<T> | Subscribable<T>
options ToSignalOptions & { initialValue?: undefined; requireSync?: false; }
Returns

Signal<T | undefined>

      
      toSignal(source: Observable<T> | Subscribable<T>, options: ToSignalOptions & { initialValue?: null; requireSync?: false; }): Signal<T | null>
    
Parameters
source Observable<T> | Subscribable<T>
options ToSignalOptions & { initialValue?: null; requireSync?: false; }
Returns

Signal<T | null>

      
      toSignal(source: Observable<T> | Subscribable<T>, options: ToSignalOptions & { initialValue?: undefined; requireSync: true; }): Signal<T>
    
Parameters
source Observable<T> | Subscribable<T>
options ToSignalOptions & { initialValue?: undefined; requireSync: true; }
Returns

Signal<T>

Get the current value of an Observable as a reactive Signal.

      
      toSignal(source: Observable<T> | Subscribable<T>, options?: ToSignalOptions & { initialValue?: U; }): Signal<T | U>
    
Parameters
source Observable<T> | Subscribable<T>
options ToSignalOptions & { initialValue?: U; }

Optional. Default is undefined.

Returns

Signal<T | U>

toSignal returns a Signal which provides synchronous reactive access to values produced by the given Observable, by subscribing to that Observable. The returned Signal will always have the most recent value emitted by the subscription, and will throw an error if the Observable errors.

With requireSync set to true, toSignal will assert that the Observable produces a value immediately upon subscription. No initialValue is needed in this case, and the returned signal does not include an undefined type.

By default, the subscription will be automatically cleaned up when the current injection context is destroyed. For example, when toSignal is called during the construction of a component, the subscription will be cleaned up when the component is destroyed. If an injection context is not available, an explicit Injector can be passed instead.

If the subscription should persist until the Observable itself completes, the manualCleanup option can be specified instead, which disables the automatic subscription teardown. No injection context is needed in this configuration as well.