Search code examples
angulartypescripthttppromisespinner

Using ngx-spinner in a http subscribe operation in Angular


I want to use a spinner in an Angular Application. I've found one called ngx-spinner. However there is not enough examples on the practical use of it. I want to use it in my http requests. How can I show hide/show the spinner correctly ?

public getCars(){
 this.spinner.show();
  this.appService.getCars().subscribe(
    car => {
      this.carList=car;
      for (let i = 0; i < this.carList.length; i++) {
        let make = this.carList[i].make;
      }
    },
  );
 this.spinner.hide();

}

I installed ngx-spinner and imported it correctly. The library is working but I just cannot use it in my http requests correctly. Any help welcomed.


Solution

  • I think you have to move "this.spinner.hide();" directly under the closing brace of the "for" statement. This is the success-callback.