fuse-angular/src/@fuse/services/splash-screen/splash-screen.service.ts
2023-05-30 09:26:50 +03:00

49 lines
1.2 KiB
TypeScript

import { DOCUMENT } from '@angular/common';
import { Inject, Injectable } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { filter, take } from 'rxjs';
@Injectable({providedIn: 'root'})
export class FuseSplashScreenService
{
/**
* Constructor
*/
constructor(
@Inject(DOCUMENT) private _document: any,
private _router: Router,
)
{
// Hide it on the first NavigationEnd event
this._router.events
.pipe(
filter(event => event instanceof NavigationEnd),
take(1),
)
.subscribe(() =>
{
this.hide();
});
}
// -----------------------------------------------------------------------------------------------------
// @ Public methods
// -----------------------------------------------------------------------------------------------------
/**
* Show the splash screen
*/
show(): void
{
this._document.body.classList.remove('fuse-splash-screen-hidden');
}
/**
* Hide the splash screen
*/
hide(): void
{
this._document.body.classList.add('fuse-splash-screen-hidden');
}
}