Pull to Refresh

Pull down from the top of a scrolling list to refresh it.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrPullToRefresh } from 'ngwr/pull-to-refresh';

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

Basic

Start the fetch on (refresh) and keep refreshing true until it settles; the button does the same without touch.

<wr-pull-to-refresh
  style="height: 16rem"
  [refreshing]="loading()"
  (refresh)="reload()"
>
  @for (item of items(); track item) {
    <div class="row">{{ item }}</div>
  }
</wr-pull-to-refresh>
protected readonly loading = signal(false);

reload(): void {
  this.loading.set(true);
  this.api.fetch().subscribe((rows) => {
    this.items.set(rows);
    this.loading.set(false);   // clearing `refreshing` closes the indicator
  });
}
Refresh programmatically
Aurora
Borealis
Cascade
Drift
Ember
Fathom

API

NameDescriptionTypeDefault
refreshingShows the spinner. Set it in refresh and clear it when the work settles.booleanfalse
thresholdPull distance (px) a release must reach to trigger.number64
disabledDisable the gesture entirely.booleanfalse
(refresh)Fires when the user pulls past threshold and releases.void—

CSS variables

Set these on the component's selector or a wrapper, not on :root: the defaults are declared on ngwr/pull-to-refresh's own element.

VariableDefaultDeclared on
--wr-pull-to-refresh-font-familyvar(--wr-font-family-base).wr-pull-to-refresh

Dependencies

Built onSpinner

See also