Search code examples
angularionic-frameworkionic4

How to implement a loading button in Ionic 4?


I want to insert into my Ionic 4 app the button, used in a form when, which once pressed show a ring/circle/spinner on the left during the waiting of the response from the server, during the operation. It is part of the Material Design, but I didn't found anything on the doc. How Can I implement?


Solution

  • The solution I suggested in the comments would look something like this:

    <ion-button (click)="doRequest()"> 
      <ion-label > <ion-spinner *ngIf="loading"></ion-spinner> Submit</ion-label>
    </ion-button>
    
    export class Component {
      loading: boolean;
    
      doRequest() {
        this.loading = true;
        this.service.makeRequest().subscribe(
          res => { 
            this.loading = false;
            // Do something else...
          }
        ); 
      }
    }
    

    UPDATE

    Changed to ion-spinner as @JanP suggested in comments