import { SpinnerService } from "./shared/components/spinner/spinner.service"; //Or where your service isexport class SomeComponent implements OnInit, OnDestroy { private loadSpinner: boolean = true; //Might even leave this out constructor( private spinnerService: SpinnerService, //Somewhere in a method... someMethod(): void { //Make it spin this.spinnerService.show(true); //Do something that takes times, then STOP it from spinning this.spinnerService.show(false);
Service
spinner-service.ts
It is already written, so you just consume it as per above
I did make it work the same now as Justus’ code, seeing that component has a working spinner 😄
App Component
app.component.ts
import { SpinnerService } from "./shared/components/spinner/spinner.service"; //Or where your service isexport class AppComponent implements OnInit, OnDestroy { loadSpinner: boolean = true; constructor( private spinnerService: SpinnerService, ngOnInit() { this.spinnerService.onSpinnerChanged$ .pipe(debounceTime(300), distinctUntilChanged(), takeWhile(() => this.alive)) .subscribe((status: boolean) => { this.loadSpinner = status; });