25 lines
417 B
TypeScript
25 lines
417 B
TypeScript
import { Injectable, signal} from '@angular/core';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class LoadingService {
|
|
|
|
private requestCount = 0;
|
|
readonly isLoading = signal(false);
|
|
|
|
show(): void {
|
|
this.requestCount++;
|
|
this.isLoading.set(true);
|
|
}
|
|
|
|
hide(): void {
|
|
this.requestCount--;
|
|
|
|
if (this.requestCount <= 0) {
|
|
this.requestCount = 0;
|
|
this.isLoading.set(false);
|
|
}
|
|
}
|
|
}
|