how do i add a loader while angular loads json data?

you need a property that keeps track of the state of the request. i.e. loadingData: boolean.

in your component you would need to set this value at the start of the request, and when it completes.

ngOnInit(): void {
  this.loading = true;
  this.dataService.getRemoteData().subscribe(data => {
    // set the status of loading to false so the template can update
    this.loading =f alse;
    console.log("Remote Data:" + JSON.stringify(data));
    //console.log(data);
    this.parseJson(data);
  });
}

finally, in the template, add an element that is shown based on the value of the loading property.

<div *ngIf="loading"><!-- Insert your progress message/animation --> </div>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top