MCPcopy Create free account
hub / github.com/angular/angular / toObservable

Function toObservable

packages/core/rxjs-interop/src/to_observable.ts:50–77  ·  view source on GitHub ↗
(source: Signal<T>, options?: ToObservableOptions)

Source from the content-addressed store, hash-verified

48 * @publicApi 20.0
49 */
50export function toObservable<T>(source: Signal<T>, options?: ToObservableOptions): Observable<T> {
51 if (ngDevMode && !options?.injector) {
52 assertInInjectionContext(toObservable);
53 }
54 const injector = options?.injector ?? inject(Injector);
55 const subject = new ReplaySubject<T>(1);
56
57 const watcher = effect(
58 () => {
59 let value: T;
60 try {
61 value = source();
62 } catch (err) {
63 untracked(() => subject.error(err));
64 return;
65 }
66 untracked(() => subject.next(value));
67 },
68 {injector, manualCleanup: true},
69 );
70
71 injector.get(DestroyRef).onDestroy(() => {
72 watcher.destroy();
73 subject.complete();
74 });
75
76 return subject.asObservable();
77}

Callers 5

CmpClass · 0.90
SecondaryNavigationClass · 0.90
NavigationClass · 0.90
TypingsLoaderClass · 0.90

Calls 11

assertInInjectionContextFunction · 0.90
injectFunction · 0.90
effectFunction · 0.90
untrackedFunction · 0.90
sourceFunction · 0.85
errorMethod · 0.65
onDestroyMethod · 0.65
getMethod · 0.65
destroyMethod · 0.65
nextMethod · 0.45
completeMethod · 0.45

Tested by

no test coverage detected