angular-spinners
Version:
Easy loading spinner management for apps running Angular 2+
44 lines (34 loc) • 989 B
text/typescript
import { Component, Input, Output, OnInit, OnDestroy, EventEmitter } from '@angular/core';
import { SpinnerService } from './spinner.service';
export class SpinnerComponent implements OnInit, OnDestroy {
constructor(private spinnerService: SpinnerService) {}
name: string;
group: string;
loadingImage: string;
private isShowing = false;
get show(): boolean {
return this.isShowing;
}
showChange = new EventEmitter();
set show(val: boolean) {
this.isShowing = val;
this.showChange.emit(this.isShowing);
}
ngOnInit(): void {
if (!this.name) throw new Error("Spinner must have a 'name' attribute.");
this.spinnerService._register(this);
}
ngOnDestroy(): void {
this.spinnerService._unregister(this);
}
}