fromEvent
Creates an Observable that emits events of a specific type coming from the given event target.
Parameters
target
The DOM EventTarget, Node.js EventEmitter, JQuery-like event target, NodeList or HTMLCollection to attach the event handler to.
eventName
The event name of interest, being emitted by the target
.
options
Optional. Default is undefined
.
Options to pass through to addEventListener
resultSelector
Optional. Default is undefined
.
Type: (...args: any[]) => T
.

import { fromEvent } from 'rxjs';
const clicks$ = fromEvent(document, 'click');
clicks$.subscribe(x => console.log(x));
// Results in:
// MouseEvent object logged to console every time a click
// occurs on the document.
Last updated
Was this helpful?