File
Implements
Metadata
selector |
lib-loader |
styleUrls |
./loader.component.scss |
templateUrl |
./loader.component.html |
Methods
Private
clearTimeOut
|
clearTimeOut()
|
|
|
Private
createTimer
|
createTimer()
|
|
|
ngOnDestroy
|
ngOnDestroy()
|
|
|
Private
_subscription
|
Type : Subscription
|
|
Private
_timeOut
|
Type : any
|
|
import {Component, Inject, OnDestroy, OnInit, PLATFORM_ID} from '@angular/core';
import {LoaderService} from './loader.service';
import {Subscription} from 'rxjs';
import {isPlatformBrowser} from '@angular/common';
@Component({
selector: 'lib-loader',
templateUrl: './loader.component.html',
styleUrls: ['./loader.component.scss']
})
export class LoaderComponent implements OnInit, OnDestroy {
public show: boolean;
public text: string;
private _timeOut: any;
private _subscription: Subscription;
constructor(
@Inject(PLATFORM_ID) private _platformId: Object,
private _loader: LoaderService
) {
this.show = false;
this.text = '';
this._subscription = new Subscription();
}
ngOnInit() {
this._subscription.add(
this._loader.getProgress().subscribe(value => {
this.text = '';
this.show = value;
if (isPlatformBrowser(this._platformId)) {
this.createTimer();
}
})
);
}
ngOnDestroy(): void {
this._subscription.unsubscribe();
}
private createTimer(): void {
if (this.show) {
if (this._timeOut) {
this.clearTimeOut();
}
this._timeOut = setTimeout(() => {
if (this.show) {
this.text = 'Esta operaciĆ³n puede durar varios minutos...';
}
clearTimeout(this._timeOut);
this._timeOut = null;
}, 60000);
} else if (this._timeOut) {
this.clearTimeOut();
}
}
private clearTimeOut(): void {
clearTimeout(this._timeOut);
this._timeOut = null;
}
}
<ng-template [ngIf]="show">
<div class="container">
<mat-card>
<mat-progress-spinner mode="indeterminate" color="primary" [diameter]="35"></mat-progress-spinner>
<ng-template [ngIf]="text !== ''">
<p>{{text}}</p>
</ng-template>
</mat-card>
</div>
</ng-template>
.container {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
z-index: 999;
display: flex;
background: rgba(255, 255, 255, 0.6);
mat-card {
padding: 16px;
margin: auto;
box-sizing: border-box;
background-color: #323232;
p {
width: 150px;
margin: 16px 0 0 0;
color: white;
font-size: 12px;
}
mat-progress-spinner {
margin: 0 auto;
}
}
}
.hidden {
display: none !important;
}
Legend
Html element with directive