# wrInView

> Emit when an element enters or leaves the viewport.

Source: https://ngwr.dev/reference/directives/in-view  
Kind: Directive  
Added in v16.7  
Optional

## Installation

Import the class. This entry point has no stylesheet.

```typescript
import { Component } from '@angular/core';
import { WrInView } from 'ngwr/directives';

@Component({ imports: [WrInView] })
export class MyComponent {}
```

## Usage

`(wrInView)` carries `true` on entering and `false` on leaving. An element that starts out of view emits nothing until it shows up.

```angular-html
<section (wrInView)="seen.set($event)" [wrInViewThreshold]="0.5">…</section>

<img wrInViewOnce (wrInView)="track()" src="hero.webp" alt="" />
```

## One observer

Every instance with the same threshold shares one `IntersectionObserver`. It is created with the first element and disconnected with the last. Nothing is observed on the server.

## API

| Name | Description | Type | Default |
| --- | --- | --- | --- |
| `(wrInView)` | `true` when the host enters the viewport, `false` when it leaves. Fires on a change only. | `boolean` | — |
| `[wrInViewThreshold]` | Share of the host, from 0 to 1, that must be visible. Read once, on first render. | `number` | `0` |
| `[wrInViewOnce]` | Stop watching after the first entry. | `boolean` | `false` |

## See also

- [Counter](https://ngwr.dev/reference/components/counter) — `wr-count-up` can wait for its number to scroll into view.
- [Reveal](https://ngwr.dev/animations/reveal) — A headline whose letters rise into place one after another from first paint, with no script: built for above the fold, where the server HTML already holds the pieces and the motion starts before the bundle arrives.
