All files / loading-spinner si-loading-spinner.service.ts

33.33% Statements 2/6
0% Branches 0/1
0% Functions 0/2
20% Lines 1/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33                    1x                                            
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
 
@Injectable({
  providedIn: 'root'
})
export class SiLoadingService {
  /**
   * Counts the number of loads active, is `0` when all loading is finished (or hasn't started).
   */
  readonly counter: BehaviorSubject<number> = new BehaviorSubject<number>(0);
 
  /**
   * Start the loading.
   */
  startLoad(): void {
    this.counter.next(this.counter.value + 1);
  }
 
  /**
   * Stop the loading.
   */
  stopLoad(): void {
    Iif (this.counter.value > 0) {
      this.counter.next(this.counter.value - 1);
    }
  }
}