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/elements/index.md.

Elements

LYNX_ELEMENTS declares every Lynx element as an Angular directive, so your templates type-check. import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

The rest of the element exports have pages of their own:

PageExports
Host and Native ElementsregisterHostElement(), registerNativeElement(), LynxElementAttributes, HostElementTag, LynxTagElement
Form AccessorsLYNX_FORM_ACCESSORS, LynxInputValueAccessor, LynxTextareaValueAccessor, LynxFieldValue, LynxFieldParseError

Usage

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

@Component({
  selector: 'app-greeting',
  imports: [LYNX_ELEMENTS],
  template: `
    <view class="card">
      <image [src]="avatar()" />
      <text>Hello from Lynx</text>
    </view>
  `,
})
export class Greeting {
  readonly avatar = signal('https://example.com/avatar.png');
}
  • Your editor's type checking and ng test need it. ng build and ng serve don't. See What the build checks.
  • Attributes are inputs. Each directive declares its element's attributes as inputs, so [src]="url()" type-checks. Bind any other attribute with [attr.name].
  • Events aren't outputs. Bind them by name, such as (bindtap). Angular still types each one's $event: see Element events. Handling taps and events shows how to bind them.

What the build checks

In a component that doesn't import LYNX_ELEMENTS, ng build and ng serve still accept Lynx's elements and the attributes their directives declare.

They do report the rest of Angular's unknown-element and unknown-property errors (NG8001 and NG8002). For example:

  • a component used in a template but left out of imports
  • a mistyped input

On the phone, these would be a blank space, or a binding that goes nowhere.

  • They're warnings with the code frame, and the build passes.
  • The elementChecks build option changes that. "error" makes them errors, as in ng test. "off" leaves them out.
  • The build reads which elements and attributes to accept from @blotch/angular-lynx's type declarations. If it can't find them, it warns and reports none of these errors, whatever elementChecks says.

HTML tags and component hosts

The runtime renders some HTML tags as Lynx elements, such as div (a <view>), span (a <text>) and img (an <image>). In ng build, they take their element's attributes too: <div [accessibility-label]="label()"> builds without a warning.

The same goes for the attributes every element takes (accessibility-label, flatten, consume-slide-event, …) on a component's host and on canvas.

ng test and the editor don't know them there. In tested code, bind them with [attr.accessibility-label], or use the Lynx element.

Native elements of your own

Native elements that your app's iOS and Android code registers aren't in LYNX_ELEMENTS. To use one, either:

  • give it a directive of your own that selects its tag and declares its attributes as inputs, as LYNX_ELEMENTS does (see LynxElementAttributes)
  • or add CUSTOM_ELEMENTS_SCHEMA to the schemas of the components that use it

At runtime

Every element's directive except input's and textarea's only declares attributes. At runtime, Angular makes no directive for those elements: the renderer sets the attributes itself. That keeps a screen of many elements quick to build.

  • So viewChild(LynxView) finds nothing. To reach an element, give it a template reference: viewChild('card', { read: ElementRef }).
  • A directive of your own can take an element's attribute. If it declares the attribute as an input, it takes the binding, and the element doesn't get it. That's how a directive's input works on the web too.
  • To give the element the attribute too, set it from your directive's host: '[attr.accessibility-label]': 'label()'.

API

LYNX_ELEMENTS

const LYNX_ELEMENTS: readonly [
  typeof LynxView,
  typeof LynxText,
  // …every directive in the table below, in this order
];

Every directive below, as one array for a component's imports. Each directive is also exported on its own.

DirectiveSelectorReference
LynxViewview<view>
LynxTexttext<text>
LynxInlineTruncationinline-truncation<text>
LynxImageimage<image>
LynxScrollViewscroll-view<scroll-view>
LynxListlist<list>
LynxListItemlist-item<list>
LynxBlockblock<block>
LynxIfifNo page
LynxForforNo page
LynxFrameframe<frame>
LynxInputinput<input>
LynxTextareatextarea<textarea>
LynxInputValueAccessorinput with a form directiveForm Accessors
LynxTextareaValueAccessortextarea with a form directiveForm Accessors
LynxOverlayoverlay<overlay>
LynxRefreshrefresh<refresh>
LynxRefreshHeaderrefresh-header<refresh>
LynxScrollCoordinatorscroll-coordinator<scroll-coordinator>
LynxScrollCoordinatorHeaderscroll-coordinator-header<scroll-coordinator>
LynxScrollCoordinatorSlotscroll-coordinator-slot<scroll-coordinator>
LynxScrollCoordinatorSlotDragscroll-coordinator-slot-drag<scroll-coordinator>
LynxScrollCoordinatorToolbarscroll-coordinator-toolbar<scroll-coordinator>
LynxSvgsvg<svg>
LynxViewPagerviewpager<viewpager>
LynxViewPagerItemviewpager-item<viewpager>
LynxBlurViewblur-view<blur-view>
LynxVideovideo<video>
LynxWebViewwebview<webview>
LynxCoverViewcover-view<cover-view>
LynxTitleBarViewtitle-bar-view<title-bar-view>
LynxAppleSignInButtonapple-sign-in-button<apple-sign-in-button>
LynxRouterLinkActive[routerLinkActive]Routing
LynxAccessibilityTraits[lynxAccessibilityTraits]Accessibility
LynxListFor*lynxListFor<list>

LynxIf and LynxFor

@Directive({ selector: 'if' })
class LynxIf {}

@Directive({ selector: 'for' })
class LynxFor {}

Declare Lynx's own low-level <if> and <for> elements, so a template that contains them type-checks.

  • They're unrelated to Angular's @if and @for blocks.
  • AngularLynx doesn't test them. Use @if and @for instead.

Attributes on every element

Every directive above also accepts these inputs, except:

  • the two form accessors
  • LynxRouterLinkActive, LynxAccessibilityTraits and LynxListFor

Write the true/false ones either way: flatten="false" and [flatten]="false" both give Lynx a boolean. The same goes for the numbers of pan-intercept-direction and pan-intercept-scope.

AttributeTypeDescription
idstringElement ID. Selector queries find elements by it.
namestringA name some Lynx APIs use to find the element.
user-interaction-enabledbooleanWhether the element receives touch events. Default true.
native-interaction-enabledbooleanWhether the element receives the platform's own gestures.
event-throughbooleanLets touches pass through to the elements below.
hit-slopstring | objectExtends the touch area beyond the element's box.
block-native-eventbooleanWhether the element consumes native iOS and Android gestures.
ignore-focusbooleanStops the element from taking focus.
ios-enable-simultaneous-touchbooleanLets iOS recognize this touch together with others.
flattenbooleanAndroid only. false gives the element its own native view. Default true.
pan-intercept-direction0 | 1Takes pan gestures from views outside Lynx in this direction: horizontal or vertical.
pan-intercept-scope0–5Which outside views pan-intercept-direction takes pans from.
consume-slide-event[number, number][]Swipe angle ranges the element keeps from platform gestures.
enable-touch-pseudo-propagationbooleanLets :active also apply to ancestors.
accessibility-*, a11y-idSee Accessibility.
exposure-*See Exposure.

Types

BaseLynxElement

type BaseLynxElement = {
  animate(
    keyframes: Record<string, string | number>[],
    options?: number | LynxAnimationOptions,
  ): BaseLynxAnimation;
  invoke(methodName: string, params?: Record<string, unknown>): void;
  focus(options?: FocusOptions): void;
  blur(): void;
  setAccessibilityTrait(trait: string, on: boolean): void;
  // …and the methods the renderer uses
};

The nativeElement of an element's ElementRef. It's AngularLynx's wrapper around the native element, not a DOM element. Type an ElementRef with it to call its methods:

readonly option = viewChild.required<ElementRef<BaseLynxElement>>('option');
  • animate() starts an animation. See Animation.
  • invoke() calls one of the element's UI methods, such as scrollTo. If you call it before the element is on screen, such as from ngAfterViewInit(), it waits until it is.
  • focus() and blur() give an <input> or <textarea> the focus and take it away, as on the web. Focus opens the keyboard. Other elements have no focus, and nothing happens. Signal Forms' focusBoundControl() calls focus().
  • setAccessibilityTrait() adds a trait to the element's own accessibility-traits, or takes it away. LynxAccessibilityTraits does the same from a template.