The source the contains the target to listen to. Can be window, document, body, or an element ref, or anything else Renderer2 can listen to.
The name of the event to listen to.
The selector to run when the event is emitted that will be output by the signal.
Optional
options: EventSignalOptions<T> & { Options used when creating the signal.
const $viewElem = viewChild('div');
const $bodyEvent = eventSignal('body', 'click', (event) => event.clientX);
const $divEvent = eventSignal($viewElem, 'click', (event) => event.clientX);
effect(() => console.log(`body: ${$bodyEvent()}`)); // initially undefined.
effect(() => console.log(`div: ${$divEvent()}`)); // initially undefined.
Creates a signal that listens to a DOM object event and maps the event to a value. Requires being in an injection context.
The source the contains the target to listen to. Can be window, document, body, or an element ref, or anything else Renderer2 can listen to.
The name of the event to listen to.
The selector to run when the event is emitted that will be output by the signal.
Options used when creating the signal.
const $viewElem = viewChild('div');
const $bodyEvent = eventSignal('body', 'click', (event) => event.clientX, { initialValue: 0 });
const $divEvent = eventSignal($viewElem, 'click', (event) => event.clientX, { initialValue: 0 });
effect(() => console.log(`body: ${$bodyEvent()}`)); // initially 0.
effect(() => console.log(`div: ${$divEvent()}`)); // initially 0.
Creates a signal that listens to a DOM object event and returns that event. Requires being in an injection context.
The source the contains the target to listen to. Can be window, document, body, or an element ref, or anything else Renderer2 can listen to.
The name of the event to listen to.
Optional
options: EventSignalOptions<any> & { Options used when creating the signal.
Creates a signal that listens to a DOM object event and maps the event to a value, initially returning undefined if default is not set. Requires being in an injection context.