liveBook · Manning

outputFromObservable

As explained in Modern Angular

outputFromObservable is an Angular interoperability function that exposes emissions from an RxJS observable as a component or directive output.

outputFromObservable exposes an RxJS observable as a component or directive output. It preserves ordinary parent template event binding while separating RxJS interoperability from the core output API. section 10.3.4

Use it when an existing observable already represents an outward event stream. Unlike a legacy @Output-decorated observable, the modern form makes the RxJS dependency explicit by importing outputFromObservable from @angular/core/rxjs-interop rather than @angular/core. section 10.3.4

Expose container clicks

A component can turn clicks on a referenced container element into a clicked output. A parent continues to consume it with (clicked)="handleClick($event)", while the child derives the events with RxJS fromEvent. section 10.3.4

@ViewChild('containerElement') containerElement: ElementRef<HTMLDivElement>;
clicked = outputFromObservable(fromEvent(this.containerElement, 'click'));

This replacement keeps an observable-backed clicked output without decorating the observable with @Output. section 10.3.4

How Modern Angular covers it

How deep it goes
Contrasts legacy decorated observables with a direct migration to outputFromObservable, without detailing its internals.
Examples
Demonstrates forwarding clicks from a ViewChild container through fromEvent as a clicked output.
What it assumes
Assumes familiarity with Angular outputs, template event bindings, and RxJS observables.
What you can do after
Apply it via @angular/core/rxjs-interop to expose an observable as an Angular output.
How it connects
Connects RxJS observables, @Output, output, EventEmitter, parent event binding, and two-way binding.

This explainer was generated by Manning's knowledge graph from the text of Modern Angular. The section links point to the parts of the book it draws on.