BACK
Referenceinterval
Reference · 04

interval

Emits an incrementing number every N milliseconds.

Signature

interval(period: number, scheduler?: SchedulerLike): Observable

Marble diagram

interval(10):  --0--1--2--3-- ...

What it does

Every period milliseconds it emits 0, then 1, 2, … It never completes on its own — an "endless" stream. The first value comes after period, not immediately (for an immediate start see timer(0, period)).

When to use

Timers, polling, simple animation, periodic status checks. Almost always combined with take, takeUntil, or switchMap so the stream can be ended.

Gotcha

Without unsubscription or a limiter, the interval ticks forever, keeping the component in memory. In Angular components use takeUntilDestroyed() or takeUntil(destroy$).

See also

timer, take, takeUntil

script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...