I have an angular 4 application and I get datas from a database with a springboot application. When I open my application, there is a get which returns data to display on the first page. So, I want to display a progress spinner while the datas are loading and when the datas are loaded, remove the spinner and display the datas.
So, I don't know how to do that.
For now, this is my html code (the datas are displayed in visTimeline
:
<md-spinner id="isLoadingSpinner" style="margin:0 auto;"></md-spinner>
<visTimeline (myTask)="returnTask($event)" [tasks]="tasks"></visTimeline>
And the ts code :
ngOnInit() {
this.tasks = this.datasService.getTasks();
if(this.datasService.isLoading == false){
document.getElementById("isLoadingSpinner").style.display = "none";
}
}
And this is the get in the datas.service :
getAffectationsFromDataBase() {
this.http.get('http://localhost:8081/affectation/findAll').map((response:Response) => {
this.tasks.tasks = this.transformAffectations(response.json().affectations);
}).subscribe(result => this.isLoading = false);
}
So, I try with if in the ngOnInit function and with a while but it doesn't work. Do you know how I can do that ?