# new NgxMediaService()
The NgxMediaService provides utilities for observing and managing media-related features
such as color scheme detection, window resize events, and dynamic SVG injection. It leverages
Angular's dependency injection system and RxJS for reactive programming.
Service for managing media-related features in an Angular application.
Example
// Inject the service into a component
constructor(private mediaService: NgxMediaService) {}
// Observe the current color scheme
this.mediaService.colorScheme$.subscribe(scheme => {
console.log('Current color scheme:', scheme);
});
// Observe window resize events
this.mediaService.resize$.subscribe(dimensions => {
console.log('Window dimensions:', dimensions);
});
Members
# _document
This getter provides access to the global document object, ensuring it is properly typed.
Retrieves the global document object.
# _window
This getter provides access to the global window object, ensuring it is properly typed.
Retrieves the global window object.
# angularZone
This service is used to optimize performance by running certain operations outside Angular's zone and bringing updates back into the zone when necessary.
Angular's NgZone service for running code outside Angular's zone.
# colorScheme$
This observable emits the current color scheme (light or dark) and updates whenever
the system's color scheme preference changes or the DARK_PALETTE_CLASS is toggled.
Observable that emits the current color scheme of the application.
Observable.<WindowColorScheme>
# colorScheme$
This observable emits the current color scheme (light or dark) and updates whenever
the system's color scheme preference changes or the DARK_PALETTE_CLASS is toggled.
Observable that emits the current color scheme of the application.
# currentSchema
This property holds the current color scheme (light, dark, or undefined) and is updated whenever the color scheme changes.
Tracks the current color scheme of the application.
# destroy$
This subject is used to complete observables and clean up resources when the service is destroyed.
It is utilized with the takeUntil operator to manage subscriptions.
Subject used to signal the destruction of the service.
# resize$
This observable emits the current dimensions of the window (width and height) and updates whenever the window is resized.
Observable that emits the current dimensions of the window.
Observable.<IWindowResizeEvent>
# resize$
This observable emits the current dimensions of the window (width and height) and updates whenever the window is resized.
Observable that emits the current dimensions of the window.
# resizeSubject
This subject holds the current dimensions of the window (width and height) and emits updates
whenever the window is resized. It is used to provide the resize$ observable.
BehaviorSubject to track the window's dimensions.