import { Component } from '@angular/core';
import { WrInView } from 'ngwr/directives';
@Component({ imports: [WrInView] })
export class MyComponent {}wrInView
Emit when an element enters or leaves the viewport.
Installation
Import the class. This entry point has no stylesheet.
Usage
(wrInView) carries true on entering and false on leaving. An element that starts out of view emits nothing until it shows up.
<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
Component Counter`wr-count-up` can wait for its number to scroll into view.Animation RevealA 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.