mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-04-27 02:23:10 +00:00
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import { MediaChange, ObservableMedia } from '@angular/flex-layout';
|
|
import { Injectable } from '@angular/core';
|
|
import { BehaviorSubject } from 'rxjs';
|
|
|
|
@Injectable()
|
|
export class FuseMatchMediaService
|
|
{
|
|
activeMediaQuery: string;
|
|
onMediaChange: BehaviorSubject<string> = new BehaviorSubject<string>('');
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param {ObservableMedia} _observableMedia
|
|
*/
|
|
constructor(
|
|
private _observableMedia: ObservableMedia
|
|
)
|
|
{
|
|
// Set the defaults
|
|
this.activeMediaQuery = '';
|
|
|
|
// Initialize
|
|
this._init();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Private methods
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Initialize
|
|
*
|
|
* @private
|
|
*/
|
|
private _init(): void
|
|
{
|
|
this._observableMedia
|
|
.subscribe((change: MediaChange) => {
|
|
if ( this.activeMediaQuery !== change.mqAlias )
|
|
{
|
|
this.activeMediaQuery = change.mqAlias;
|
|
this.onMediaChange.next(change.mqAlias);
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|