@amirsavand/ngx-common - v5.4.0
    Preparing search index...

    Function animateCounter

    • Smoothly animates a numeric signal from 0 up to a target value over a given duration.

      This function creates an interval-based animation that increments a number in small steps until it reaches the target. It’s useful for counters, stats, or any UI element where you want a smooth counting animation.

      Parameters

      • target: number

        The final value the counter should reach.

      • signal: WritableSignal<number | null>

        The Angular writable signal that will be updated during the animation.

      • Optionalduration: number = 1000

        The total duration of the animation in milliseconds. Defaults to 1000ms (1 second).

      • Optionalsteps: number = 30

        The number of animation steps. Higher values result in smoother but more frequent updates.

      Returns number

      The interval timer ID, which can be used to cancel the animation using clearInterval().

      import { signal } from '@angular/core';

      const count = signal<number | null>(null);
      animateCounter(1000, count, 2000, 60);