Counter

An animated number: rolling digits or an eased count.

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 { WrCountUp, WrCounter } from 'ngwr/counter';

@Component({ imports: [WrCountUp, WrCounter] })
export class MyComponent {}

Odometer

Digits roll on every change of value.

<wr-counter [value]="123456" mode="odometer" />
123,456Randomize

Tween

mode="tween" eases from the old value to the new one.

<wr-counter [value]="9.99" mode="tween" [decimals]="2" prefix="$" />
$420.69Randomize

Padded integer

minIntegerDigits pads the number with leading zeros.

<wr-counter [value]="42" [minIntegerDigits]="6" mode="odometer" />
000,000Step

Count up

<wr-count-up> counts from from to to on load or, with trigger="visible", when it scrolls into view.

<!-- With easing="spring", duration is in seconds. -->
<wr-count-up [to]="1000" easing="spring" [duration]="2" trigger="visible" />
1,000

Count down

direction="down" counts from to to from.

<wr-count-up [from]="0" [to]="60" direction="down" />
0

Counter API

NameDescriptionTypeDefault
valuerequiredThe number to show. Coerced like every other numeric input here — it was the only one without it, and Intl.NumberFormat().format(NaN) renders the literal text NaN.number—
modeAnimation mode.WrCounterMode'odometer'
durationDuration (ms).number900
decimalsFixed number of decimals.number0
prefixOptional prefix (e.g. '$').string''
suffixOptional suffix (e.g. '%').string''
groupingGroup thousands.booleantrue
minIntegerDigitsPad integer part to at least this many digits.number0 (no padding)

Count-up API

NameDescriptionTypeDefault
fromStarting value.number0
torequiredTarget value.number—
durationAnimation duration, in the units its easing reads, or null for that easing's own default: - ease-out — milliseconds (default 1200, min 100) - spring — seconds, tuning the stiffness (default 2, min 0.05)number | nullnull
delayOptional delay (ms) before the animation starts.number0
easingAnimation curve.WrCountUpEasing'ease-out'
triggerWhen to start the animation. - 'mount' (default) — start as soon as the component is rendered. - 'visible' — wait for the host to enter the viewport (IntersectionObserver). Useful for long pages or hero numbers below the fold.WrCountUpTrigger'mount'
directionCounting direction. 'down' swaps from ↔ to.WrCountUpDirection'up'
decimalsFixed number of decimals.number0
prefixOptional prefix (e.g. '$').string''
suffixOptional suffix (e.g. '%').string''
groupingDisable grouping separators (1,234 → 1234).booleantrue (grouping on)
(started)Emits when the animation begins.void—
(completed)Emits when the animation settles.void—

Dependencies

Used byStatistic

See also