fuse-angular/src/app/main/main.component.ts

61 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Component, ElementRef, HostBinding, Inject, OnDestroy, OnInit, Renderer2, ViewEncapsulation } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { FuseConfigService } from '../core/services/config.service';
import { Platform } from '@angular/cdk/platform';
import { DOCUMENT } from '@angular/common';
2017-07-12 12:35:07 +00:00
@Component({
2017-08-02 08:53:30 +00:00
selector : 'fuse-main',
templateUrl : './main.component.html',
styleUrls : ['./main.component.scss'],
2017-07-15 15:03:40 +00:00
encapsulation: ViewEncapsulation.None
2017-07-12 12:35:07 +00:00
})
2017-08-02 08:53:30 +00:00
export class FuseMainComponent implements OnInit, OnDestroy
2017-07-12 12:35:07 +00:00
{
onSettingsChanged: Subscription;
fuseSettings: any;
@HostBinding('attr.fuse-layout-mode') layoutMode;
2017-07-12 12:35:07 +00:00
2017-08-18 09:31:17 +00:00
constructor(
private _renderer: Renderer2,
private _elementRef: ElementRef,
private fuseConfig: FuseConfigService,
private platform: Platform,
@Inject(DOCUMENT) private document: any
2017-08-18 09:31:17 +00:00
)
2017-07-12 12:35:07 +00:00
{
this.onSettingsChanged =
this.fuseConfig.onSettingsChanged
.subscribe(
(newSettings) => {
this.fuseSettings = newSettings;
this.layoutMode = this.fuseSettings.layout.mode;
}
);
if ( this.platform.ANDROID || this.platform.IOS )
{
this.document.body.className += ' is-mobile';
}
2017-07-12 12:35:07 +00:00
}
ngOnInit()
{
}
ngOnDestroy()
{
this.onSettingsChanged.unsubscribe();
}
2017-08-18 09:31:17 +00:00
addClass(className: string)
{
this._renderer.addClass(this._elementRef.nativeElement, className);
}
removeClass(className: string)
{
this._renderer.removeClass(this._elementRef.nativeElement, className);
}
2017-07-12 12:35:07 +00:00
}