> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Elements

`LYNX_ELEMENTS` declares every Lynx [element](/guide/glossary.md#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:

| Page                                                                      | Exports                                                                                                               |
| ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| [Host and Native Elements](/api/angular-lynx/elements/host-and-native.md) | `registerHostElement()`, `registerNativeElement()`, `LynxElementAttributes`, `HostElementTag`, `LynxTagElement`       |
| [Form Accessors](/api/angular-lynx/elements/form-accessors.md)            | `LYNX_FORM_ACCESSORS`, `LynxInputValueAccessor`, `LynxTextareaValueAccessor`, `LynxFieldValue`, `LynxFieldParseError` |

## Usage

```typescript title="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](#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](/api/angular-lynx/element-events.md). [Handling taps and events](/guide/elements/event-handling.md) 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](/api/build/index.md#build-options) 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](#attributes-on-every-element) (`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`](/api/angular-lynx/elements/host-and-native.md#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`

```typescript
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.

| Directive                       | Selector                         | Reference                                                                   |
| ------------------------------- | -------------------------------- | --------------------------------------------------------------------------- |
| `LynxView`                      | `view`                           | [`<view>`](/api/elements/view.md)                                           |
| `LynxText`                      | `text`                           | [`<text>`](/api/elements/text.md)                                           |
| `LynxInlineTruncation`          | `inline-truncation`              | [`<text>`](/api/elements/text.md)                                           |
| `LynxImage`                     | `image`                          | [`<image>`](/api/elements/image.md)                                         |
| `LynxScrollView`                | `scroll-view`                    | [`<scroll-view>`](/api/elements/scroll-view.md)                             |
| `LynxList`                      | `list`                           | [`<list>`](/api/elements/list.md)                                           |
| `LynxListItem`                  | `list-item`                      | [`<list>`](/api/elements/list.md)                                           |
| `LynxBlock`                     | `block`                          | [`<block>`](/api/elements/block.md)                                         |
| `LynxIf`                        | `if`                             | [No page](#lynxif-and-lynxfor)                                              |
| `LynxFor`                       | `for`                            | [No page](#lynxif-and-lynxfor)                                              |
| `LynxFrame`                     | `frame`                          | [`<frame>`](/api/elements/frame.md)                                         |
| `LynxInput`                     | `input`                          | [`<input>`](/api/elements/input.md)                                         |
| `LynxTextarea`                  | `textarea`                       | [`<textarea>`](/api/elements/textarea.md)                                   |
| `LynxInputValueAccessor`        | `input` with a form directive    | [Form Accessors](/api/angular-lynx/elements/form-accessors.md)              |
| `LynxTextareaValueAccessor`     | `textarea` with a form directive | [Form Accessors](/api/angular-lynx/elements/form-accessors.md)              |
| `LynxOverlay`                   | `overlay`                        | [`<overlay>`](/api/elements/overlay.md)                                     |
| `LynxRefresh`                   | `refresh`                        | [`<refresh>`](/api/elements/refresh.md)                                     |
| `LynxRefreshHeader`             | `refresh-header`                 | [`<refresh>`](/api/elements/refresh.md)                                     |
| `LynxScrollCoordinator`         | `scroll-coordinator`             | [`<scroll-coordinator>`](/api/elements/scroll-coordinator.md)               |
| `LynxScrollCoordinatorHeader`   | `scroll-coordinator-header`      | [`<scroll-coordinator>`](/api/elements/scroll-coordinator.md)               |
| `LynxScrollCoordinatorSlot`     | `scroll-coordinator-slot`        | [`<scroll-coordinator>`](/api/elements/scroll-coordinator.md)               |
| `LynxScrollCoordinatorSlotDrag` | `scroll-coordinator-slot-drag`   | [`<scroll-coordinator>`](/api/elements/scroll-coordinator.md)               |
| `LynxScrollCoordinatorToolbar`  | `scroll-coordinator-toolbar`     | [`<scroll-coordinator>`](/api/elements/scroll-coordinator.md)               |
| `LynxSvg`                       | `svg`                            | [`<svg>`](/api/elements/svg.md)                                             |
| `LynxViewPager`                 | `viewpager`                      | [`<viewpager>`](/api/elements/viewpager.md)                                 |
| `LynxViewPagerItem`             | `viewpager-item`                 | [`<viewpager>`](/api/elements/viewpager.md)                                 |
| `LynxBlurView`                  | `blur-view`                      | [`<blur-view>`](/api/elements/blur-view.md)                                 |
| `LynxVideo`                     | `video`                          | [`<video>`](/api/elements/video.md)                                         |
| `LynxWebView`                   | `webview`                        | [`<webview>`](/api/elements/webview.md)                                     |
| `LynxCoverView`                 | `cover-view`                     | [`<cover-view>`](/api/elements/cover-view.md)                               |
| `LynxTitleBarView`              | `title-bar-view`                 | [`<title-bar-view>`](/api/elements/title-bar-view.md)                       |
| `LynxAppleSignInButton`         | `apple-sign-in-button`           | [`<apple-sign-in-button>`](/api/elements/apple-sign-in-button.md)           |
| `LynxRouterLinkActive`          | `[routerLinkActive]`             | [Routing](/api/angular-lynx/routing/index.md#lynxrouterlinkactive)          |
| `LynxAccessibilityTraits`       | `[lynxAccessibilityTraits]`      | [Accessibility](/api/angular-lynx/accessibility.md#lynxaccessibilitytraits) |
| `LynxListFor`                   | `*lynxListFor`                   | [`<list>`](/api/elements/list.md#lynxlistfor)                               |

### `LynxIf` and `LynxFor`

```typescript
@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`.

| Attribute                         | Type                 | Description                                                                           |
| --------------------------------- | -------------------- | ------------------------------------------------------------------------------------- |
| `id`                              | `string`             | Element ID. Selector queries find elements by it.                                     |
| `name`                            | `string`             | A name some Lynx APIs use to find the element.                                        |
| `user-interaction-enabled`        | `boolean`            | Whether the element receives touch events. Default `true`.                            |
| `native-interaction-enabled`      | `boolean`            | Whether the element receives the platform's own gestures.                             |
| `event-through`                   | `boolean`            | Lets touches pass through to the elements below.                                      |
| `hit-slop`                        | `string \| object`   | Extends the touch area beyond the element's box.                                      |
| `block-native-event`              | `boolean`            | Whether the element consumes native iOS and Android gestures.                         |
| `ignore-focus`                    | `boolean`            | Stops the element from taking focus.                                                  |
| `ios-enable-simultaneous-touch`   | `boolean`            | Lets iOS recognize this touch together with others.                                   |
| `flatten`                         | `boolean`            | Android only. `false` gives the element its own native view. Default `true`.          |
| `pan-intercept-direction`         | `0 \| 1`             | Takes pan gestures from views outside Lynx in this direction: horizontal or vertical. |
| `pan-intercept-scope`             | `0`–`5`              | Which 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-propagation` | `boolean`            | Lets `:active` also apply to ancestors.                                               |
| `accessibility-*`, `a11y-id`      |                      | See [Accessibility](/api/angular-lynx/accessibility.md#attributes).                   |
| `exposure-*`                      |                      | See [Exposure](/api/angular-lynx/exposure.md#attributes).                             |

## Types

### `BaseLynxElement`

```typescript
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:

```typescript
readonly option = viewChild.required<ElementRef<BaseLynxElement>>('option');
```

- **`animate()`** starts an animation. See [Animation](/api/angular-lynx/animation.md).
- **`invoke()`** calls one of the element's [UI methods](/guide/glossary.md#ui-method), 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`](/api/angular-lynx/accessibility.md#lynxaccessibilitytraits) does the same from a template.

## Related

- [Elements and layout](/guide/elements/index.md): which element to use, and how they differ from HTML.
- [Handling taps and events](/guide/elements/event-handling.md)
- [Forms](/guide/forms.md)
- [Accessibility](/api/angular-lynx/accessibility.md) and [Exposure](/api/angular-lynx/exposure.md): the shared attributes in detail.
