MCPcopy
hub / github.com/angular/angular / toObservable

Function toObservable

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

Source from the content-addressed store, hash-verified

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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…