RxJS - Creation Operator fromEventPattern



This operator will create an observable from the input function that is used to register event handlers.

Syntax

fromEventPattern(addHandler_func: Function): Observable

Parameters

addHandler_func − The argument given is addHandler_func, this will be attached to the actual event source.

Return value

Returns an observable when the event happens, for example, click, mouseover, etc.

Example

import { fromEventPattern } from 'rxjs';

function addBtnClickHandler(handler) {
   document.getElementById("btnclick").addEventListener('click', handler);
}

const button_click = fromEventPattern(addBtnClickHandler);
button_click.subscribe(
   x => console.log(
      "ClientX = "+ x.clientX + " and ClientY="+ x.clientY
   )
);

Output

fromEventPattern
Advertisements