Question presented to candidate:
"A search box component debounces keystrokes with RxJS and needs to expose the result as an output. Explain output(), outputFromObservable() and outputToObservable(), and how this differs from putting an EventEmitter behind @Output()."
What a strong answer should cover:
output()is imperative: you callemit().outputFromObservable(obs$)is declarative: every value the observable pushes is an event.- Both implement
OutputRef; the parent binds either one with(search)="...". outputFromObservablesubscribes to the source once per listener, so a cold source or an expensive pipe runs per listener unless shared.- Completion stops the output; errors are not handled by Angular, so catch them in the pipe.
outputToObservable(ref)goes the other way, for consumers that want RxJS operators.@Output()withEventEmitterwas a Subject you pushed into; these APIs keep RxJS optional and tie subscriptions to the component lifecycle.
Clarifying questions expected:
- "Is the source observable hot or cold, and could more than one listener attach?"
Code / implementation expected: Yes β a component with one output() and one outputFromObservable() fed by a debounced pipeline.