injectMediaQuery
projects/common/layout/observers/inject-media-query.ts
Description#
Inject-form of CngxMediaQuery: returns a reactive
Signal<boolean> that reflects whether the host window currently matches
a CSS media query, without needing a host element.
Use it where the directive form has nowhere to attach - inside a route
guard, a store, a computed(), or any injection context that reacts to a
viewport or preference query. For host-bound templates, prefer the
[cngxMediaQuery] directive; for pure styling, prefer CSS @media /
@container.
Wraps window.matchMedia(): seeds the signal from MediaQueryList.matches,
updates on the change event, and removes the listener via DestroyRef
when the injection scope is destroyed. In SSR / non-DOM environments (no
defaultView or no matchMedia) it returns a static false signal and
wires no listener, so it never throws off the browser.
Returns a Signal<boolean> - never an Observable; the reactive boundary
stays inside cngx.