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

# `<viewpager>`

Full-width pages the user swipes between horizontally, like a carousel or an onboarding flow.

## Usage

```typescript title="src/app/onboarding.ts"
import { Component, signal } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-onboarding',
  imports: [LYNX_ELEMENTS],
  template: `
    <viewpager
      style="width: 100%; height: 300px;"
      (bindchange)="current.set($event.detail.index)"
    >
      @for (page of pages; track page) {
        <viewpager-item>
          <text>{{ page }}</text>
        </viewpager-item>
      }
    </viewpager>
    <text>Page {{ current() + 1 }} of {{ pages.length }}</text>
  `,
})
export class Onboarding {
  readonly pages = ['Welcome', 'Sync', 'Done'];
  readonly current = signal(0);
}
```

Import `LYNX_ELEMENTS` in your component (see [Elements](/api/angular-lynx/elements/index.md)).

:::warning
Needs [XElement](/guide/glossary.md#xelement) in custom native apps (see [Embedding](/guide/embedding/index.md)).
:::

## Attributes

| Attribute                      | Type      | Default | Description                                                                                                                                    |
| ------------------------------ | --------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `initial-select-index`         | `number`  | `0`     | Page shown first.                                                                                                                              |
| `enable-scroll`                | `boolean` | `true`  | Whether the user can swipe between pages.                                                                                                      |
| `bounces`                      | `boolean` | `true`  | iOS only. Bounce past the first and last pages.                                                                                                |
| `keep-item-view`               | `boolean` | `false` | iOS and Android. Keeps the views of off-screen pages attached instead of releasing them.                                                       |
| `android-always-overscroll`    | `boolean` | `false` | Android only. Bounce past the first and last pages.                                                                                            |
| `android-force-can-scroll`     | `boolean` | `false` | Android only. At the first and last pages, keeps the swipe from passing to a parent.                                                           |
| `ios-gesture-direction`        | `boolean` | `false` | iOS only. At the first and last pages, lets an outer horizontal scroll view take the swipe.                                                    |
| `ios-gesture-offset`           | `number`  | `0`     | iOS only. Width in px of a strip at the left edge where the pager ignores swipes, so the system swipe-back gesture works there.                |
| `ios-recognized-gesture-class` | `string`  | —       | iOS only. Class name of a native gesture recognizer in the [host app](/guide/glossary.md#host-app) that may run at the same time as the pager. |
| `ios-recognized-view-tag`      | `number`  | `0`     | iOS only. Tag of the native view that owns that gesture recognizer.                                                                            |

Plus the [common attributes](/api/elements/view.md#attributes), such as `id`, `class` and `style`.

## Events

Read the payload from `$event.detail`. Angular types `$event` for each event: see [Element events](/api/angular-lynx/element-events.md#other-elements).

| Event              | `detail`                                | Description                                                                                      |
| ------------------ | --------------------------------------- | ------------------------------------------------------------------------------------------------ |
| `bindchange`       | `{ index: number; isDragged: boolean }` | The pager settled on page `index`. `isDragged` is `true` when the user swiped there.             |
| `bindwillchange`   | `{ index: number; isDragged: boolean }` | The pager is about to move to page `index`.                                                      |
| `bindoffsetchange` | `{ offset: number }`                    | Fires during a swipe. `offset` is the position in pages: `0.5` is halfway between pages 0 and 1. |

Plus the [common events](/api/elements/view.md#events), such as `bindtap`.

## Methods

This **UI method** ([Glossary](/guide/glossary.md#ui-method)) changes the page from code. Call it with `invoke()` on the element (see [Call element methods](/guide/selector-query.md)).

| Method      | Parameters                            | Description                                                    |
| ----------- | ------------------------------------- | -------------------------------------------------------------- |
| `selectTab` | `{ index: number; smooth?: boolean }` | Moves to page `index`. It animates unless `smooth` is `false`. |

```typescript
import { Component, ElementRef, viewChild } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-slides',
  imports: [LYNX_ELEMENTS],
  template: `
    <viewpager #pager style="width: 100%; height: 300px;">
      <viewpager-item><text>One</text></viewpager-item>
      <viewpager-item><text>Two</text></viewpager-item>
    </viewpager>
    <view (bindtap)="next()"><text>Next</text></view>
  `,
})
export class Slides {
  readonly pager = viewChild.required('pager', { read: ElementRef });

  next(): void {
    this.pager().nativeElement.invoke?.('selectTab', { index: 1 });
  }
}
```

## Children

Wrap each page in a **`<viewpager-item>`**. Every direct child must be one.

## Related

- [`<scroll-coordinator>`](/api/elements/scroll-coordinator.md): tabs of lists under a collapsing header
- [Tabs](/dolan/tabs.md): a UI component for switching views
- [Call element methods](/guide/selector-query.md)
