Base solution for your next web application
Open Closed

Show loader, the angular way #4019


User avatar
0
ajayak created

How can I show loader when an HTTP call is made and hide when the call is completed?

In general case, I have an ApiBaseService class which is inherited by other ApiServices and the loading implementation is written in ApiBaseService. But in AspNetZero, api calls are made using auto-generated proxy service class. How can I show a common loader?


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ajayak,

    You can use such a pattern

    this.saving = false;
     this._yourService.yourMethod(this.model)
                .finally(() => { this.saving = false; })
                .subscribe(() => {
                    //handle success here
                });
    

    and you can use saving parameter for showing/hiding your loader image.

  • User Avatar
    0
    xitix created

    Above solution is not working for me, kindly suggest for showing loader for my method as given below. getCqrDashboard_NG() : void{ this._personService.getZMZWDashboard(this.zoneID, this.assetID, this.assetType, this.locationStatus, this.serviceStatus, this.status, this.retailerID, this.dNNUserID, this.area, this.pageNumber, this.pageSize) .subscribe((response) => { this.cqrDashboardLogs = response.items; console.log(this.cqrDashboardLogs); }); }

    Error shown below: