For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/angular-lynx/element-events.md.

Element events

The type of $event on every Lynx element event. Angular infers it in your templates, so a misspelt detail field fails the build. import type { LynxEvent, ImageLoadDetail } from '@blotch/angular-lynx';

Usage

src/app/photo.ts
import { Component, signal } from '@angular/core';
import {
  type ImageLoadDetail,
  LYNX_ELEMENTS,
  type LynxEvent,
} from '@blotch/angular-lynx';

@Component({
  selector: 'app-photo',
  imports: [LYNX_ELEMENTS],
  template: `
    <image [src]="url" (bindload)="loaded($event)" />
    <text>{{ size()?.width }} × {{ size()?.height }}</text>
  `,
})
export class Photo {
  readonly url = 'https://example.com/photo.jpg';
  readonly size = signal<ImageLoadDetail | null>(null);

  loaded({ detail }: LynxEvent<ImageLoadDetail>): void {
    this.size.set(detail);
  }
}
  • In a template, write nothing. Angular knows each element's events: in (bindload)="size.set($event.detail)", $event is already LynxEvent<ImageLoadDetail>.
  • For a handler declared in the class, type its parameter with LynxEvent and the event's detail type, from the tables below.
  • Every prefix has the same type. (catchtap), (capture-bindtap) and (global-bindtap) get what (bindtap) gets, and so on for every event.
  • An event the element doesn't fire stays the DOM Event, such as (bindload) on a <view>.
  • $event isn't a DOM Event. A handler that takes Event no longer compiles: change its parameter to the type below.

API

LynxEvent

type LynxEvent<Detail = unknown> = {
  readonly type: string;
  readonly timestamp: number;
  readonly target: LynxEventTarget;
  readonly currentTarget: LynxEventTarget;
  readonly detail: Detail;
  stopPropagation(): void;
  preventDefault(): void;
};
FieldDescription
typeThe event's name without its prefix, such as 'load'.
timestampWhen the event fired, in milliseconds. It's timestamp, not the DOM's timeStamp.
targetThe element the event started on.
currentTargetThe element whose handler is running.
detailThe event's own data. LynxEvent with no Detail has detail: unknown: for events with none, such as bindstartplay.
stopPropagation(), preventDefault()Do nothing. Use the catch prefix to stop an event (see Handling taps and events).

LynxEventTarget

type LynxEventTarget = {
  readonly id: string;
  readonly uid: number;
  readonly dataset: Readonly<Record<string, unknown>>;
};

Plain data, not the element: it has no methods. id is the element's id attribute, uid Lynx's internal number for it, and dataset its data-* attributes without the data- prefix. A dataset value is unknown because a property binding, such as [data-item]="item", keeps its value's type.

Events every element fires

Event$event
bindtap, bindlongpress, bindtouchstart, bindtouchmove, bindtouchend, bindtouchcancelTouchEvent from @lynx-js/types
bindmousedown, bindmouseup, bindmousemove, bindmouseenter, bindmouseleaveMouseEvent from @lynx-js/types
bindlayoutchangeLynxEvent<LayoutChangeDetail>
binduiappear, binduidisappearLynxEvent<UIAppearanceDetail>
bindanimationstart, bindanimationiteration, bindanimationend, bindanimationcancelAnimationEvent from @lynx-js/types
bindtransitionstart, bindtransitionend, bindtransitioncancelTransitionEvent from @lynx-js/types
bindaccessibilityactionLynxEvent<AccessibilityActionDetail>

TouchEvent has the same fields as LynxEvent<{ x: number; y: number }>, plus touches and changedTouches. Import it, and the other @lynx-js/types events, by name: without the import, TypeScript uses the DOM's TouchEvent. The detail types are on <view>.

Pointer events

(pointerdown), (pointermove), (pointerup), (pointercancel), (pointerover), (pointerout), (pointerenter), (pointerleave), (gotpointercapture) and (lostpointercapture) work on every element, without a bind prefix, as in a browser. Lynx sends only touches, so AngularLynx makes each touch into the pointer events a browser fires for one, in the same order, and $event is a DOM PointerEvent: each finger is a pointer (pointerId), pointerType is 'touch', and offsetX/offsetY are relative to the element. Libraries written for the web listen for these, such as angular-three for taps on a 3D scene.

A touch's events go to the element it started on, wherever the finger moves, as if every pointer were captured; setPointerCapture() changes only hasPointerCapture() and the capture events. In the web preview, they're the browser's own pointer events, including a mouse's. A (click), which is Lynx's bindtap, has the offsetX and offsetY of where the pointer lifted, on an element with pointer listeners.

A finger keeps its pointerId until it lifts, at the element and at the document. With multi-touch off, the LynxView's default, there's one touch at a time, and its pointerId is 0.

(mouseover), (mouseenter), (mouseout) and (mouseleave) come from the first finger too, as a phone's browser makes them from a tap: mouseover and mouseenter when it touches the element, after pointerenter, and mouseout and mouseleave when it lifts, after pointerleave. Code written for a mouse's hover, such as Angular's @defer (on hover), runs when a finger touches the element. Only the element hears them: document:mouseover never runs on iOS or Android. In the web preview, they're the browser's own.

document:, window: and body: listeners

Host listeners on the document, the window and the body work as in a browser, and so do the libraries written for the browser that use them:

@Component({
  selector: 'app-tilt',
  host: { '(document:pointermove)': 'tilt($event)' },
  template: `…`,
})
export class Tilt {
  readonly angle = signal(0);

  tilt(event: PointerEvent): void {
    this.angle.set((event.clientX / window.innerWidth - 0.5) * 30);
  }
}

An element's ownerDocument is a document that hears the screen's events, and inject(DOCUMENT) is the same object. Its defaultView is window. So document.addEventListener(), window.addEventListener() and RxJS's fromEvent(document, 'click') hear them too.

TargetEvents
document:, window:pointerdown, pointermove, pointerup, pointercancel, pointerover and pointerout, touchstart, touchmove, touchend and touchcancel, and click, for a touch anywhere on screen
window:resize, when the LynxView changes size, as when the device rotates
body:Those of the page element, which every element is in: the events that bubble up to it
  • They run after the touched element's listeners and the body's, as in a browser. A capturing listener, { capture: true }, runs before them.
  • They hear a touch that a (catchtap) or another catch handler stopped. In a browser, stopPropagation() hides an event from the document. On Lynx they still hear it, on the next timer, after every listener of that touch.
  • A pointer event's target is the element touched, the nativeElement of its ElementRef, and its offsetX/offsetY are relative to that element. A touch event and a click are Lynx's own event objects, as an element's listeners get them.
  • window.innerWidth and window.innerHeight are the LynxView's size in CSS pixels. Until its first layout, they're the screen's, from SystemInfo.
  • iOS and Android send no mouse events, so document:mousemove never runs there: listen for pointermove.
  • In the web preview, they're the browser's own events inside the <lynx-view>, a mouse's included, and the size is the <lynx-view>'s. Key events are the page's.

Each element's own events

The fields of each detail type are in its element's Events table.

<image> and <svg>

Event$event
bindloadLynxEvent<ImageLoadDetail>
binderror (<image>)LynxEvent<ImageErrorDetail>
bindstartplay, bindcurrentloopcomplete, bindfinalloopcomplete (<image>)LynxEvent

See <image> and <svg>.

<text>

Event$event
bindlayoutLynxEvent<TextLayoutDetail>
bindselectionchangeLynxEvent<TextSelectionChangeDetail>

See <text>.

<input> and <textarea>

Event$event
bindinputLynxEvent<InputDetail>
bindfocus, bindblur, bindconfirmLynxEvent<InputValueDetail>
bindselectionLynxEvent<InputSelectionDetail>
bindbeforeinputLynxEvent<BeforeInputDetail>
bindkeyboardheightchangeLynxEvent<KeyboardHeightDetail>
bindkeyboardLynxEvent<KeyboardDetail>
bindline (<textarea>)LynxEvent<TextareaLineDetail>

See <input> and <textarea>.

<scroll-view>

Event$event
bindscroll, bindscrollend, bindscrolltoupper, bindscrolltolower, bindscrolltoupperedge, bindscrolltoloweredge, bindscrolltonormalstate, bindcontentsizechangedLynxEvent<ScrollDetail>

See <scroll-view>.

<list>

Event$event
bindscroll, bindscrolltoupper, bindscrolltolowerLynxEvent<ListScrollDetail>
bindscrollstatechangeLynxEvent<ListScrollStateChangeDetail>
bindlayoutcompleteLynxEvent<ListLayoutCompleteDetail>
bindsnapLynxEvent<ListSnapDetail>

ListScrollDetail adds <list>'s fields to ScrollDetail. ListAttachedCell and ListItemInfo are the types of its item arrays. See <list>.

Other elements

ElementEvent$event
<frame>bindloadLynxEvent<FrameLoadDetail>
<frame>bindloadmetricsLynxEvent<FrameLoadMetricsDetail>
<overlay>bindshowoverlay, binddismissoverlay, bindrequestcloseLynxEvent
<overlay>bindoverlaytouchLynxEvent<OverlayTouchDetail>
<overlay>binderrorLynxEvent<OverlayErrorDetail>
<refresh>bindstartrefreshLynxEvent<RefreshStartDetail>
<refresh>bindheaderoffsetLynxEvent<RefreshHeaderOffsetDetail>
<refresh>bindrefreshstatechangeLynxEvent<RefreshStateChangeDetail>
<scroll-coordinator>bindoffsetLynxEvent<ScrollCoordinatorOffsetDetail>
<video>bindfirstframeLynxEvent<VideoFirstFrameDetail>
<video>bindtimeupdateLynxEvent<VideoTimeUpdateDetail>
<video>bindbufferingLynxEvent<VideoBufferingDetail>
<video>binderrorLynxEvent<VideoErrorDetail>
<video>bindplaying, bindpaused, bindstopped, bindended, bindloopedLynxEvent
<viewpager>bindchange, bindwillchangeLynxEvent<ViewPagerChangeDetail>
<viewpager>bindoffsetchangeLynxEvent<ViewPagerOffsetChangeDetail>
<webview>bindloadLynxEvent
<webview>binderrorLynxEvent<WebViewErrorDetail>
<webview>bindmessageLynxEvent<WebViewMessageDetail>
<webview>bindopenwindow, bindlocationchangeLynxEvent<WebViewUrlDetail>
  • The other elements fire only the common events, such as <view>, <blur-view> and <list-item>.