Service

WrMedia

Signal-backed viewport queries. Named breakpoints mirror _breakpoints.scss; raw matchMedia strings work too.

Install

import { WrMedia, provideWrMedia } from 'ngwr/media';

// Optional — override breakpoints (defaults match _breakpoints.scss).
bootstrapApplication(AppComponent, {
  providers: [provideWrMedia({ md: 720 })],
});

Usage

private readonly media = inject(WrMedia);

protected readonly isMd = this.media.matches('md');
protected readonly isWide = this.media.matches('(min-width: 1200px)');
protected readonly current = this.media.current; // 'xs' | 'sm' | ...
Current breakpoint: xs
matches('md'): false
matches('lg'): false
Resize the window — values update live.

Why ngwr provides this

matchMedia is imperative and needs manual listener cleanup; this exposes breakpoint queries as signals that just work in templates and computed().

API

NameDescriptionTypeDefault
matches(query)Signal<boolean> for a named breakpoint or raw matchMedia query. Cached + SSR-safe.(q: WrBreakpoint | string) => Signal<boolean>
currentActive breakpoint key — xs / sm / md / lg / xl / xxl.Signal<WrBreakpoint>
provideWrMedia(breakpoints?)Override the breakpoint map. Partial — merged with defaults.(map?: Partial<WrBreakpointMap>) => EnvironmentProviders

See also