I am trying to show a spinner on my application while the data is loaded fully. So what I did is subscribe to the web service call. I have a variable called IsBusy which is set to True before I make the service call. Upon completion of the web service call I am setting IsBusy to false.
In my html I am using this IsBusy to show/hide my spinner. Right now it does not display spinner at all. Below is my html and typescript code.
<div id="surgeryRequestFormContainer" class="container-fluid">
<div *ngIf="isBusy" class="loading">
<img src="http://thinkfuture.com/wp-content/uploads/2013/10/loading_spinner.gif" />
</div>
<div class="row">
<div class="form-group col-sm-12">
<button kendoButton (click)="btnPrevious()">Previous</button>
<button kendoButton (click)="btnNext()">Next</button>
<button kendoButton (click)="btnSaveForLater()">Save For Later</button>
</div>
</div>
I researched before posting and read somewhere that I may need to import ChangeDetectorRef from '@angular/core'. I did that and instantiated ChangeDetectorRef as cd in my constructor.
ngOnInit(): void {
this.isBusy = true;
console.log("before the subscribe " + this.isBusy);
this.route.params
.switchMap((params: Params) => this._RequestFormService.getRequestById(+params['id']))
.subscribe(
data => this.Model = data,
error => console.log("Error", error),
() => this.isBusy = false);
this.isBusy = false;
console.log(this.isBusy);
this.cd.detectChanges(); // marks path
}
I am not sure what I need to do in order to show/hide my spinner div tag.