Documentation

on()

Adds an event listener for the specified event name.

on(
eventName: string,
handle: string | ViewBuilderEventHandler<TView, any>,
): void;

Parameters

Description

This method adds a listener for events with the specified name on all view instances. Multiple listeners can be added for the same event.

If a string is provided, a transformed event with that name is emitted. The original event is still emitted on the view (other listeners on the same view will see it), but it does not propagate to parent objects — only the transformed event does. The new event includes the original event data and references the original event via the inner property.

If a function is provided, it will be called with the event and the view instance. The function can return true or call event.stopPropagation() to stop the event from propagating to parent objects.

Related