exercises

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

busy.service.ts (865B)


      1 import { Injectable, signal } from "@angular/core";
      2 import { Observable, finalize } from "rxjs";
      3 
      4 @Injectable({ providedIn: 'root' })
      5 export class BusyService {
      6     private static instance: BusyService;
      7     readonly busy = signal<boolean>(false);
      8     readonly message = signal<string>('Loading...');
      9 
     10     constructor() {
     11         BusyService.instance = this;
     12     }
     13     
     14     public static get Instance(): BusyService {
     15         // Simple guard for early access, though providedIn: 'root' should prevent this.
     16         if (!BusyService.instance) {
     17             throw new Error('BusyService not initialized. Ensure it is provided in root.');
     18         }
     19         return BusyService.instance;
     20     }
     21 
     22     show(message: string = 'Loading...'): void {
     23         this.message.set(message);
     24         this.busy.set(true);
     25     }
     26 
     27     hide(): void {
     28         this.busy.set(false);
     29     }
     30 }