forked from angular/flex-layout
-
-
Notifications
You must be signed in to change notification settings - Fork 2
MatchMedia
Alessio Bianchini edited this page Dec 18, 2025
·
1 revision
MatchMedia is the low-level service used by the library to observe media query activations.
In most cases you should prefer MediaObserver for app-level responsive state.
Use MatchMedia only for advanced/custom flows.
import { MatchMedia } from 'ng-flex-layout/core';
constructor(private matchMedia: MatchMedia) {
matchMedia.observe(['(min-width: 600px)']).subscribe(change => {
// change.matches, change.mediaQuery
});
}observeAsSignal() is a convenience wrapper around toSignal(matchMedia.observe(...)).
import { Injector, effect, inject } from '@angular/core';
import { MatchMedia } from 'ng-flex-layout/core';
export class MyCmp {
private readonly injector = inject(Injector);
private readonly matchMedia = inject(MatchMedia);
readonly mq = this.matchMedia.observeAsSignal(['(min-width: 600px)'], { injector: this.injector });
constructor() {
effect(() => {
const change = this.mq();
// react to change.matches
});
}
}-
Quick Links
-
Documentation
-
Demos
-
StackBlitz Templates
-
Learning FlexBox
-
History
-
Developer Guides
-
Contributing