Angular uses the @Output
decorator and the EventEmitter
class to emit events to the parent component. But you can use RxJS streams instead.
The EventEmitter
class is actually a wrapper around the RxJs Subject class. If you have an existing Subject or Observable that you want to use as an output, you can directly use it with the @Output
decorator.
export class SearchComponent {
// With Angular EventEmitter
@Output()
search = new EventEmitter<string>();
// With RxJs Subject / Observable
@Output()
search = this.form.valueChanges.pipe(
debounceTime(500),
map((value) => value.term),
distinctUntilChanged()
);
}